You enter urls' into a text area on another page, when you click submit these urls get loaded into an array. The for loop should work through every element in the array, saving each picture with its basename.
For some reason it will only save the first image. I have traced the issue to the file_put_conten ts(). As shown from my test echo's the names of the files are being assigned correctly, but the file_put_conten ts will not save more than one image.
Below is the code...
The script will echo that all images have been uploaded, but only one will be saved into the folder. Thank you for all your help
Also this error is shown when you try and upload more than one url
Warning:
For some reason it will only save the first image. I have traced the issue to the file_put_conten ts(). As shown from my test echo's the names of the files are being assigned correctly, but the file_put_conten ts will not save more than one image.
Below is the code...
Code:
<?php
$info = "";
if(isset($_POST['uploadfilepic'])){
$info = $_POST["com"];
$DIR = './images/products/';
$data = explode("\n", $info);
foreach($data as $hop){
$imgName = basename($hop);
$filename = ($DIR . $imgName);
$url = file_get_contents($hop);
if(!empty($url)){
file_put_contents($filename, $url);
Echo " Upload of " .$imgName." was a success! <br/><br/>";
}
else
echo $imgName." Upload Failed";
}
}
?>
Also this error is shown when you try and upload more than one url
Warning:
file_put_conten ts(./images/products/b9de9e86e4e55e1 2744975d05c1b93 608bdeeb9537718 e19b3d0c7cbf932 78b0_400_400.jp g ) [function.file-put-contents]: failed to open stream: Invalid argument in C:\wamp\www\cat alog\imgcom.php on line 21