Page 1 of 1
Download some images from link to local server
Posted: Fri Jun 11, 2010 1:06 pm
by Dss.Lexius
Hi,
i am just new to PHP and need some help. i hope i 'll get.
actually, i want to automate my work.
there are some images hosted on a server (around 10 images) i have their links.
i want to download those images (*.jpg & *.gif files) to my local server in some directory!
can anyone help me?
Thanks!
Re: Download some images from link to local server
Posted: Fri Jun 11, 2010 2:16 pm
by Dss.Lexius
Ok, before anyone reply
i have got it, but still need some help
can anyone modify this to download multiple images using variables
Code: Select all
<?php
$image_get = "http://www.39dollarglasses.com/store/images/thumb/2164_Brown.jpg";
$image_save = "some_name.jpg";
$i = file_get_contents($image_get);
$f = fopen($image_save,'w+');
fwrite($f,$i);
fclose($f);
?>
something like this
Code: Select all
$image_get[0] = "http://www.site.com/store/images/1_a.jpg";
$image_get[1] = "http://www.site.com/store/images/2_b.jpg";
and then save them with their original name as got from download link.
?
Re: Download some images from link to local server
Posted: Fri Jun 11, 2010 2:50 pm
by lunarnet76
you have an array so
you declare an array containing ALL your images URL
Code: Select all
$image_get =array( "http://www.site.com/store/images/1_a.jpg", "http://www.site.com/store/images/2_b.jpg");
at the beginning then you read your all array and for each image you download it
Code: Select all
foreach($image_get as $image){
$i = file_get_contents($image);
$f = fopen($image_save,'w+');
fwrite($f,$i);
fclose($f);
}
hope it helps!
Re: Download some images from link to local server
Posted: Fri Jun 11, 2010 5:40 pm
by Dss.Lexius
Thanx, but i have 10 images. how do i put 10 links in array?
do i have to add all links in one line? the line 'll get very bigger...
Re: Download some images from link to local server
Posted: Sat Jun 12, 2010 5:35 pm
by whiteulver
Use it like this
Code: Select all
$image_get =array(
"http://www.site.com/store/images/1_a.jpg",
"http://www.site.com/store/images/2_b.jpg",
"http://www.site.com/store/images/3_c.jpg",
"http://www.site.com/store/images/4_d.jpg"
);