0

I am downloading image from url using php. here is my code

$filenameIn = $_POST['url'];

$contentOrFalseOnFailure = file_get_contents($filenameIn);


$byteCountOrFalseOnFailure = file_put_contents($filenameOut, $contentOrFalseOnFailure);

Its works fine. Now problem is that my image url is on my live server for example website name is www.umair.com and image address is www.umair.com/image.jpg now file_get_contents($filenameIn) is not working.

Error is:

Warning: file_get_contents(www.umair.com/image.jpg): failed to open stream: No such file or directory in

4
  • 1
    Based on the warning, you're missing http:// Here's a quick fix $filenameIn = "http://" .$_POST['url']; Commented Sep 2, 2014 at 16:40
  • There is problem with web server configuration. Http:// is not adding. Btw thanks Commented Sep 2, 2014 at 17:00
  • Brother its working fine on my local pc by using xampp but on live server its not working ? Commented Sep 2, 2014 at 17:06
  • You'll need to ask the people who have given you answers. Once it's been solved, mark their answer as accepted. Commented Sep 2, 2014 at 17:12

2 Answers 2

2

image address is www.umair.com/image.jpg

No it isn't, it is http://www.umair.com/image.jpg. And, if that doesn't work (with the http://) then you must not have the fopen URL wrapper enabled.

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

4 Comments

Brother its working fine bt there is one more problem. My images were uploaded by ftp on my server . Now i am downloading image through URL from my server. I cant download image on the same server. Any other server its working fine. But problem is downloading from my server.
@umair Why do you want to download an image from the server you're on through the HTTP server? Why not just open it directly? In any case, you would need to give more information... what error are you getting? Why isn't it working? What do your web server logs say?
i am searching for same image from my data-bank for the testing purpose i give url of image that is already on my server. Than this image is not downloading through file_get_content. any other image from any server downloaded successfully. I dnt have permission for web server log
umair - did you check the filesystem configuration I outlined in my answer?
2

Try using the full pathname of the webserver. (ie: http://www.umair.com).

Note example #1 here: http://php.net/manual/en/function.file-get-contents.php

Further, take a look at the runtime configuration for opening URL's: http://php.net/manual/en/filesystem.configuration.php

Comments

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.