I need to save an image from a PHP URL to my PC.
Let's say I have a page, http://example.com/image.php
, holding a single "flower" image, nothing else. How can I save this image from the URL with a new name (using PHP)?
If you have
Else use cURL:
|
|||||||||||||||||||||
|
|
|||||||||||||||||||||
|
Here you go, the example saves the remote image to image.jpg.
|
|||||||||||||
|
I wasn't able to get any of the other solutions to work, but I was able to use wget:
|
|||
|
Create a folder named images located in the path you are planning to place the php script you are about to create. Make sure it has write rights for everybody or the scripts won't work ( it won't be able to upload the files into the directory). |
|||
|
Vartec's answer with cURL didn't work for me. It did, with a slight improvement due to my specific problem. e.g., When there is a redirect on the server (like when you are trying to save the facebook profile image) you will need following option set:
The full solution becomes:
|
|||||||||
|
|
||||
|
|
|||||||||||||||||||||
|
http://php.net/manual/ru/function.file.php
|
|||||
|
protected by Community♦ Mar 14 '12 at 19:18
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?