PHP: download images from array of urls? -


i'm trying download images array , store them on server using php.

this php code:

$images = 'http://url.com/image.jpg, http://url.com/image2.jpg, http://url.com/image-test.jpg, http://url.com/image6.jpg, http://url.com/image.jpg';  $images = array(''.$images.'');   foreach($images $name=>$image) {      $name = explode(",", $image);      $name0 = implode(" ",$name);      copy(''.$name0.'', '/test/'.$name0.'.jpg');        } 

when run code, don't images stored on server , warning message on php page.

could please advise on issue?

the warning message this:

warning: copy(/test/http:/url.com/image.jpg http:/url.com/image2.jpg in line 88 

and on line 88:

copy(''.$name0.'', '/test/'.$name0.'.jpg');  

try following:

$images = 'http://url.com/image.jpg, http://url.com/image2.jpg, http://url.com/image-test.jpg, http://url.com/image6.jpg, http://url.com/image.jpg';  $images = explode(', ',$images);   foreach($images $image) {     $name = basename($image);    $newfile = $_server['document_root'] .'/test/'.$name;     if(copy($image, $newfile)){       echo 'successfully downloaded '. $image;    }else{       echo 'download failed '. $image;    }  } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -