For some reason it will only save the first image. I have traced the issue to the file_put_contents(). As shown from my test echo's the names of the files are being assigned correctly, but the file_put_contents will not save more than one image.
Below is the code...
Expand|Select|Wrap|Line Numbers
- <?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_contents(./images/products/b9de9e86e4e55e12744975d05c1b93608bdeeb9537718e19b3 d0c7cbf93278b0_400_400.jpg ) [function.file-put-contents]: failed to open stream: Invalid argument in C:\wamp\www\catalog\imgcom.php on line 21