There are many ways to get the remote images to your server using PHP script, but I have found the following GetImage class most useful for downloading images from a remote location to your server.
The easiest is to use PHP5 copy method like this:
copy('http://www.remotewebsite.com/image.jgp','data/image.jpg');
This is incredibly simple way to download image to your website, but this method requires allow_url_fopen is on in php.ini
Another way is to use cURL. Before going any further, Download the GetImage class from here.
This class makes this process very easy, and you can use either cURL or GD method to download remote image.
//remote image to copy
$remoteImageURL = 'http://www.website.com/image.jpg';
//local directory to store image
$dir_path = '/images/';
if($remoteImageURL){
require_once('class.get.image.php');
// initialize the class
$image = new GetImage;
// just an image URL
$image->source = $remoteImageURL;
$image->save_to = $dir_path; // with trailing slash at the end
$get = $image->download('curl'); // using cURL
$pic = $dir_path.basename($remoteImageURL);
//you can use the picture path e.g. Insert into DB from this variable $pic
Hope that helps
Cheers!
hi
php Class very good, i am using thanks
Nice Work
google +1
Excellent post! I tried using copy() function many times but it didn’t work. After reading this post, I used GetImage class and it worked well. Again, thanks so much. 🙂