t.bkh t.bkh - 5 months ago 59
JSON Question

how to use file_put_contents function into loops?

I want to get multi images from their urls and I want to save them in a directory.
I've used

as you see.but it just puts one of the images.
Is it a better way to us this function in loops or is it another function to use instead of
in loop?

include "config.php";
//open ssl:
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,

$url = 'https://www.instagram.com/' . $name . '/media/';
$content = file_get_contents($url, false, stream_context_create($arrContextOptions));
$json = json_decode($content, true);

chmod($name, 0600);
for ($i = 0; $i <= 19; $i++) {
$a = $json['items'][$i]['images']['thumbnail']['url'];
$content = file_get_contents($a);
file_put_contents($name . '/image.jpg', $content);

Answer Source

Change the filename to:

file_put_contents($name. '/image_'.$i.'.jpg', $content);

Then they will stop overwriting each other.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download