获取远程图像缩略图和链接与PHP

Hi I am trying to get the thumbnails from this site http://imgur.com/gallery to display on my php page and I want the thumbnails to be clickable so they direct the user to the imgur comment page that has the preview of the image. Do I use cURL to fetch the images? How would I set a filesize limit for the ammount of thumbnails the script saves? Thanks for any help.

It's best to go through a site's API if possible. "Scraping" a website is generally frowned upon, and often against their ToS.

I'm not sure if Imgur's API meets your needs, but I would start there.

First, you should not attempt to scrape data directly from the page. Imgur has an API that you should use. You will need to register an application and use the authentication tokens they provide. You can read more under the "Registration" category, the second one down:

https://api.imgur.com/oauth2

Once you have that, you can make calls to the endpoint of your choice:

https://api.imgur.com/endpoints/gallery

I don't have an application account so I'm not sure exactly what the response is going to look like but you can probably do something like this to at least get started:

$clientID = 'PUT YOUR CLIENT ID HERE';
header("Authorization: Client-ID $clientID");
$url = 'https://api.imgur.com/3/gallery/hot/viral/0.json';
$file = file_get_contents($url);
$json = json_decode($file, true);
print_r($json);

$json will likely be a combination of traditional and associative arrays which you can address using $json[0] or $json['key'] or chain together using $json['key'][0]['img'] and so on.

Unfortunately without registering my own application I can't be more help. If you can provide a sample of their JSON response, I or others can likely be of more assistance.