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

5
  • Dear i have put this question here because i don't understand the error Commented Jan 7, 2013 at 7:13
  • Does Apache have good rights to create the file /var/www/ajaxForm/loading.gif ? Commented Jan 7, 2013 at 7:13
  • yes the file is already created and the apache has permissions to read and write Commented Jan 7, 2013 at 7:15
  • similar question on SO : stackoverflow.com/questions/6306935/… Commented Jan 7, 2013 at 7:22
  • @RohitGoel Have you seen the answer below. Commented Jan 7, 2013 at 8:16

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.