Download image from a web (direct link) with PHP
Hey, I've got a bunch of URLs in a .txt file, lets say:
www.example.com/image1.png
www.example.com/image2.png www.example.com/image3.png www.example.com/image4.png www.example.com/image5.png ... www.example.com/image900.png
I want, with PHP, t开发者_开发知识库o read that list and save those images to a folder.
Reading that list line by line is easy, but I've got no idea how to save them to disk.Thanks!
I imagine it might be possible like this:
file_put_contents('/dest/file.png',file_get_contents('http://src.com/image.png'));
use combination of file_get_contents() and file_put_contents()
I would use Perl rather than php as PHP needs a webserver and perl can do it directly
but you can use Curl as follows
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Try file_get_contents() to fetch images then fwrite() to 'save' them.
精彩评论