I am creating custom functionality to import list of images on my server from their url. The issue is some images are copied and some images file size is 0B. If i open that image url in browser it shows me correct image.
I am using copy function to copy image:
copy($img, DIR_IMAGE.'catalog/'.$filename);
Where $img contains http url of image and $filename contain basename of image.
I also tried another alternate:
$file = fopen ($img, "rb");
if ($file)
{
$newf = fopen (DIR_IMAGE.'catalog/'.$filename, "wb");
if ($newf)
while(!feof($file))
{
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file)
{
fclose($file);
}
if ($newf)
{
fclose($newf);
}
Can anyone suggest me how to fix this issue.
Thanks in Advance.