View Full Version : Load Remote Images then Upload to Server

10-26-2009, 06:13 PM
So using range and foreach, I displayed a bunch of images from a remote website on a page. The script I used is posted below. Now, I want to somehow upload them directly to my server and then rename them (which I already know how to do). Can someone please tell me if this is entirely possible, if so, how can I [grab remote files and directly upload them to my server]?

$n = $_GET['n'];

foreach (range('1','692') as $number) {
echo '<img src="http://mywebsite.com/' . $n . '/prefix_' .$number . '.png" />';

foreach (range('1','692') as $number) {
$oldname = "prefix_" . $number . ".png";
$newname = $number . ".png";

10-26-2009, 06:29 PM
Probably the easiest way is to use PHP GD.

You loop through the remote images and simply create from PNG and save.

like this:


// Destination directory path.

// Loop through the remote image URL list that you have ...

$filename = "http://www.mysite.com/whatever.png"
$im = imagecreatefrompng($filename);

// process it here if you wish.
// resize, 24bit conversions, opacity, etc.

//And save it

// clear memory

// end of loop


Phil Jackson
10-26-2009, 06:38 PM
or use file_get_contents() and just write it to a file.

10-26-2009, 06:43 PM
You could also use copy().

copy( 'http://www.example.com/images/their_image.png', './my_image.png' );