Created
February 18, 2016 20:34
-
-
Save h4cc/81e654caf189c168e89b to your computer and use it in GitHub Desktop.
Downloading all images from a imgur gallery with a simple PHP Script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ID of gallery, you get it from URL. | |
$galleryId = 'nuAM3'; | |
$url = 'http://imgur.com/ajaxalbums/getimages/'.$galleryId.'/hit.json?all=true'; | |
$jsonContent = file_get_contents($url); | |
$data = json_decode($jsonContent, true); | |
if(!is_dir('images_'.$galleryId)) { | |
mkdir('images_'.$galleryId); | |
} | |
foreach($data['data']['images'] as $image) { | |
$name = $image['hash'].$image['ext']; | |
$imageContent = file_get_contents('http://i.imgur.com/'.$name); | |
file_put_contents('images_'.$galleryId.'/'.$name, $imageContent); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment