Created
June 2, 2020 10:57
-
-
Save lattespirit/71d1e8a025cdf1cc5673006775722f51 to your computer and use it in GitHub Desktop.
Download unsplash images 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
{ | |
"require": { | |
"kitetail/zttp": "^0.6.0" | |
} | |
} |
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 | |
use Zttp\Zttp; | |
require 'vendor/autoload.php'; | |
for ($page = 1; $page <= 10; $page++) { | |
$images = Zttp::get("https://unsplash.com/napi/search/photos?query=pasta&xp=&page={$page}&per_page=20")->json(); | |
foreach ($images['results'] as $image) { | |
file_put_contents( | |
"./images/{$image['id']}.jpg", | |
file_get_contents($image['urls']['raw']) | |
); | |
} | |
} | |
echo 'Done'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment