Jump to content

Fetch Image thumbnails and links from site


SkullandBones

Recommended Posts

How do I fetch a webpages thumbnails and the links that they point to and print it out onto one of my web pages? I'm trying to get thumbnails from imgurs gallery. I used this code so far but it just gives me the whole page and the links that the thumbnails point to dont work.

<?php
// URLs we want to retrieve
$urls = array(
    'http://imgur.com/gallery'
);
 
// initialize the multihandler
$mh = curl_multi_init();
 
$channels = array();
foreach ($urls as $key => $url) {
    // initiate individual channel
    $channels[$key] = curl_init();
    curl_setopt_array($channels[$key], array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true
    ));
 
    // add channel to multihandler
    curl_multi_add_handle($mh, $channels[$key]);
}
 
// execute - if there is an active connection then keep looping
$active = null;
do {
    $status = curl_multi_exec($mh, $active);
}
while ($active && $status == CURLM_OK);
 
// echo the content, remove the handlers, then close them
foreach ($channels as $chan) {
    echo curl_multi_getcontent($chan);
    curl_multi_remove_handle($mh, $chan);
    curl_close($chan);
}
 
// close the multihandler
curl_multi_close($mh);

?>

Thanks for any help.

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.