Download some images from link to local server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dss.Lexius
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2010 12:18 pm

Download some images from link to local server

Post 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!
Dss.Lexius
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2010 12:18 pm

Re: Download some images from link to local server

Post 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.

?
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Download some images from link to local server

Post 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!
Dss.Lexius
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2010 12:18 pm

Re: Download some images from link to local server

Post 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...
whiteulver
Forum Newbie
Posts: 3
Joined: Fri Jul 17, 2009 7:36 pm

Re: Download some images from link to local server

Post 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"
                 );
Post Reply