Copy Image from Remote Server Over HTTP
If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:
copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');
This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.
How to copy images from a remote server to a local machine in Python
Can be done using numerous ways. I prefer using request
module as u mentioned that images are accessible over http.
import requests
img = open('ur_file_name.jpg', 'wb')
img.write(requests.get('http://url_of_image_in_remote_server.jpg').content)
img.close()
This will save the image in current working directory (cwd). If u wish to save images in folder other than cwd then refer to the python's os.path
documentation.
PS: If the number of images are very high and u r hitting someone elses server, which u dont own, then its advisable to not flood the server with too many requests in short span of time. Its not encouraged (at least I don't).
Preferred way to copy JPG files from a remote server using PHP
if all you want is a copy, copy() is better.
using the gd library functions (imagecreatefromjpeg/imagejpeg) will end up re-compressing the image (probably, maybe it's smart enough not to, but probably). If you wanted to convert the images to .png or something, then you'd want to use gd (or ImageMagick)
Unable to save an image from a remote server using PHP
It's because your URL get interpreted wrong. Always use {}
around variable in string:
copy("https://$_SSActiveWear_BaseURL/$image_URL", $_SERVER['DOCUMENT_ROOT']."/tmp/" . basename($image_URL));
is converted to copy("https://SSActiveWear_BaseUrl/_URL", ...)
. As you can see PHP does not find variables $_
and $image
and applies null
for them.
Correct syntax:
copy("https://{$_SSActiveWear_BaseURL}/{$image_URL}", "{$_SERVER['DOCUMENT_ROOT']}/tmp/".basename($image_URL));
Related Topics
PHP Error: Cannot Modify Header Information - Headers Already Sent
How to Get the Query Executed in Laravel 5? Db::Getquerylog() Returning Empty Array
Difference Between If () { } and If (): Endif;
Best Practice on PHP Singleton Classes
How to Prevent My Site Page to Be Loaded Via 3Rd Party Site Frame of Iframe
Listing All the Folders Subfolders and Files in a Directory Using PHP
How to Pass Extra Variables in Url With Wordpress
MySQL Join Two Tables With Comma Separated Values
PHP Script to Loop Through All of the Files in a Directory
Is It Safe to Trust $_Server['Remote_Addr']
Simple PHP Strpos Function Not Working, Why
Opening/Closing Tags & Performance
Can't Connect to Https Site Using Curl. Returns 0 Length Content Instead. What How to Do
Sqlstate[Hy000] [2002] Connection Refused Within Laravel Homestead