Examples » Bulk Image Downloader
Here is another simple example. The script below will download linked images from a page, just like Firefox's DownloadHelper add-ons. But custom script like this gives us more controls. In this case, we'll download this girl photos which size is <= 800KB.
<?php
/**
* Download JPEG files, where size is <= 800KB
*/
include 'phpWebHacks.php';
$url = 'http://www.teenshose.com/models/ksenia1/ksenia1-photos.htm';
$h = new phpWebHacks;
/* open the page */
$page = $h->get($url);
/* get all hyperlinks */
preg_match_all('/<a[^>]+href="([^"]+)"[^>]*>/siU', $page, $matches);
/* download only JPEGs less than 800KB */
foreach($matches[1] as $url)
{
$head = $h->head($url);
if ($head['Content-Type'] == 'image/jpeg' &&
$head['Content-Length'] <= 800000) {
file_put_contents('images/'.basename($url), $h->get($url));
}
}
?>
/**
* Download JPEG files, where size is <= 800KB
*/
include 'phpWebHacks.php';
$url = 'http://www.teenshose.com/models/ksenia1/ksenia1-photos.htm';
$h = new phpWebHacks;
/* open the page */
$page = $h->get($url);
/* get all hyperlinks */
preg_match_all('/<a[^>]+href="([^"]+)"[^>]*>/siU', $page, $matches);
/* download only JPEGs less than 800KB */
foreach($matches[1] as $url)
{
$head = $h->head($url);
if ($head['Content-Type'] == 'image/jpeg' &&
$head['Content-Length'] <= 800000) {
file_put_contents('images/'.basename($url), $h->get($url));
}
}
?>
The script above use head method to retrieve the resource's info. The method is useful for you to make decisions with the requested resource.