data as $item) { $name = $item->user->username; if (!file_exists($name)) { if (mkdir($name, 0777, true)) { $src = $item->images->standard_resolution->url; $caption = $item->caption->text; $url = $item->link; $likes = $item->likes->count; $comments = $item->comments->count; $images[] = array("src" => htmlspecialchars($src), "caption" => htmlspecialchars($caption), "url" => htmlspecialchars($url)); $iContent = file_get_contents($src); $tContent = "Link: " . $url . " Image link: " . $src . " Caption: " . $caption . " Likes: " . $likes . " Comments: " . $comments; file_put_contents($name . "/" . $i . ".jpg", $iContent); file_put_contents($name . "/" . $i . ".txt", $tContent); $i++; } else { die("Error"); } } elseif (file_exists($name)) { $src = $item->images->standard_resolution->url; $caption = $item->caption->text; $url = $item->link; $likes = $item->likes->count; $comments = $item->comments->count; $images[] = array("src" => htmlspecialchars($src), "caption" => htmlspecialchars($caption), "url" => htmlspecialchars($url)); $iContent = file_get_contents($src); $tContent = "Link: " . $url . " Image link: " . $src . " Caption: " . $caption . " Likes: " . $likes . " Comments: " . $comments; file_put_contents($name . "/" . $i . ".jpg", $iContent); file_put_contents($name . "/" . $i . ".txt", $tContent); $i++; } } $api = json_decode($response)->pagination->next_url; } ?>