Issue
How to downolad images from multiples urls, now it works only with one url. I think it should be array but cant make it work even with that.
<?php
$url_to_image = 'https://images.somesite.1.jpg', 'https://images.somesite.2.jpg';
$ch = curl_init($url_to_image);
$my_save_dir = 'images/';
$filename = basename($url_to_image);
$complete_save_loc = $my_save_dir . $filename;
$fp = fopen($complete_save_loc, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Can only download with one url, but i have 10 urls to be download in a row.
Solution
Hello,
You found the answer by yourself.
You must as you said put the images in an array and loop on it.
$urls = ['https://images.somesite.1.jpg', 'https://images.somesite.2.jpg'];
$my_save_dir = 'images/';
foreach ($urls as $url) {
$ch = curl_init($url_to_image);
$filename = basename($url);
$complete_save_loc = $my_save_dir . $filename;
$fp = fopen($complete_save_loc, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
Answered By - eclairia