Jump to content

[SOLVED] download image for a page script


DylanD

Recommended Posts

I want to write a script to go through a list of pages and extract and save an image from the page. An example of the page is this

 

http://www.discogs.com/release/1738      <--I want to download the album cover.

 

I have about 400 of these links so going through and saving each page would take forever.

 

Can I do this in php??

 

and example or a link to a tutorial would be great..

 

Thanks

Dylan

Link to comment
https://forums.phpfreaks.com/topic/75219-solved-download-image-for-a-page-script/
Share on other sites

Something like this should do the trick:

<?php
$c = file_get_contents("http://www.discogs.com/release/1738");
$i = preg_match("/http:\/\/www\.discogs\.com\/image\/.*\.jpeg/",$c,$match);

$im = file_get_contents($match[0]);
$h = fopen(basename($match[0]),"w");
fwrite($h,$im);
fclose($h);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.