2
<?php
//Get the file
$content = 'http://dev.aviesta.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg ';
//Store in the filesystem.
$fp = fopen('/var/www/ajaxForm/loading.gif', 'w'); 
fwrite($fp, $content);
fclose($fp);


?>

I am getting following error when i try this

Warning: fopen(/var/www/ajaxForm/loading.gif): failed to open stream: No such file or directory in /var/www/curlimage.php on line 5 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/curlimage.php on line 6 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/curlimage.php on line 7

xkeshav
  • 53,360
  • 44
  • 177
  • 245
Rohit Goel
  • 3,396
  • 8
  • 56
  • 107

2 Answers2

6

Just taken from similar question

$url = 'http://dev.aviesta.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg';
$img = 'curl/curl_image.jpg';
file_put_contents($img, file_get_contents($url));

Note : also check the directory is writable with is_writable method

References :

file_put_contents

file_get_contents

Community
  • 1
  • 1
xkeshav
  • 53,360
  • 44
  • 177
  • 245
3

Do you need to save that image? I don't know why you write this code, you can't open a gif image and write another into it. If you want to save that image then you can use

file_put_contents("imgfolder/imgID.jpg", $image); or copy($image_url, $your_path);

HADI
  • 2,829
  • 1
  • 26
  • 26
  • this is is good but i want to save the image from the url in my local folder and it should creates the files automatically – Rohit Goel Jan 07 '13 at 07:21