Download images from PHP page that loops images

Viewed 25

I am wanting to download images from a web page (.php) that seems to loop through images when the page is reloaded.

If I open the page such as example-photographer.com/library/images.php it shows a single image. No option to see others (like slideshow navigation). If I reload the page a new image appears.

I'd like to create a script of some sort that accesses the page and downloads the image presented, then continues for a given amount (say 50 images) before stopping. I have noticed that sometimes the image showing after refresh is one that has already shown before. So it seems to just pick a random one from the library.

I also noticed that when right click and downloading the image it is always the same name (image.jpeg). So I'm thinking the script would need a way to rename the file to avoid overwrite?

Thanks in advance. I have minimal experience with coding but can usually figure things out after getting a base level suggestion on how to do it.

1 Answers

You could even use for simplicity the famous $data = file_get_contents($url) to read the image then write it to a local file using file_put_contents($filename, $data).

for ($i = 0; $i < 5; $i++) {
    $url = "https://i.stack.imgur.com/RhfH5.jpg?s=48&g=1&i=$i";
    $data = file_get_contents($url);
    file_put_contents("test$i.jpeg", $data);
}
Related