zx.
zx.

Reputation: 249

Save images from URL

I have a URL that's in this format

http://site.com/image.php?id=1

Each ID is a different photo, how can I save each image for 1000 ids?

Upvotes: 1

Views: 1334

Answers (2)

Chaoley
Chaoley

Reputation: 1292

PHP has an inbuilt function for this, see http://php.net/manual/en/function.copy.php

Upvotes: 1

codaddict
codaddict

Reputation: 454922

You can do something like (assuming they are jpg imags and your id's are all consecutive):

for($i=0;$i<=1000;$i++) {
    $url = 'http://site.com/image.php?id='.$i;
    file_put_contents('image'.$i.'.jpg', file_get_contents($url));
}

Upvotes: 4

Related Questions