I have a CSV file contains a list of URLs that I want to download images. So the question is how to read CSV file line by line and run my code on each of URL.
I have links.csv file
url1.com
url2.com
url3.com
Here is my code that I want to run
$results_page = curl($url);
$img_url = scrape_between($results_page, "\"mainUrl\":\"", "\",\"dimensions\"");
$title = scrape_between($results_page, "<span id=\"productTitle\" class=\"a-size-large\">", "</span>");
$find = array('/ /', '/:/');
$replace = array('_', '');
$img_name = preg_replace($find, $replace, $title);
$data = curl($img_url);
file_put_contents('images/'.$img_name.'.jpg', $data);
Thank you!
$fileData=fopen($file,'r');
while($row=fgets($fileData)){
// can parse further $row by usingstr_getcsv
echo $row."\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With