I have written some code that accesses a website's content using cURL and stores the image urls in an array. Now I want to go through this array and download all images to a folder on my computer. How can I achieve this?
This is the code so far gets the images from the website and prints the images on my webpage.
<?php
$curl = curl_init();
$search_string = "pc%20video%20games%202020";
$url = "https://www.daraz.pk/catalog/?q=$search_string";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
preg_match_all("!https://static-01.daraz.pk/p/[^s]*?.jpg!", $result, $matches);
$images = array_values(array_unique($matches[0])); //array that contains image urls
for($i=0; $i < count($images); $i++){
echo "<div style='float: left; margin: 10 10 10 10;'>";
echo "<img src='$images[$i]' style='width:250px; height:200px;'><br/>";
echo "</div>";
}
curl_close($curl);
?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…