Hello! I am trying to save some images from hyperlinks to a folder. However I am getting this error: file_put_contents(./images-folder/): failed to open stream: No such file or directory. Here is my code:
<?php
$in_file = 'gabriel-images-urls.csv';
$destdir = './images-folder/';
while ($data = fgetcsv($fd)) {
if(!empty($data)){
$filename = $data[2];
// echo $filename. "\n";
$img=file_get_contents_curl($filename);
/*if (!is_dir('images-folder/' . $filename)) {
// dir doesn't exist, make it
mkdir('images-folder/' . $filename);
}
*/
file_put_contents('./images-folder/', $img);
//$image = "/uploads/" . $filename;
//echo $image . "\n";
}
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of
printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
I think my $desdir variable is wrong and this is the reason the images are not put in the folder