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
Post a Comment