PHP -CSV Execute and load images from url
1 answer
The code will look something like this. Please note that this code has not been tested or hardened for security.
$handle = fopen("fileUploads.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$insertSQL = "INSERT INTO myTable values ('$data[0]', '$data[1]')";
//run the sql
//download the image
$saveHandle = fopen("image".$data[0] .".jpg", "w+");
$getImageHandle = fopen($data[1], "r"); // open the image
$contents = stream_get_contents($getImageHandle); //download it
fclose($getImageHandle); //close the handle
fwrite($saveHandle, $contents); //write the contents to disk
fclose($saveHandle); //close the handle
}
fclose ($ );
>
This code assumes your csv looks like this.
+1
source to share