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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.