Hi,
I'm trying to grab an image from remote URLs and save it onto my local server.
And this is the code created. It seems that the image data is not being copied from the remote server.
<?php
//original image
$img = "http://www.myserver.com/cat.jpg";
//directory to copy to (must be CHMOD to 777)
$copydir = "images//";
$data = file_get_contents(urlencode($img),FILE_BINARY);
if( $data )
{
$file = fopen($copydir . "test.jpg", "w+");
fputs($file, $data);
fclose($file);
}
else
{
echo "file_get_contents() failed!";
}
?>
If i replace
$img = "http://www.myserver.com/cat.jpg";
with
$img = "test.jpg";
the image appears.
However, when I use an URL, the image generated is empty (0 K.
Anyone know what is the problem here? And if so, is there another way to resolve this, either by using Http streams or...?
Any help would be great