...

View Full Version : Load Remote Images then Upload to Server



CanHasPotato
10-26-2009, 07: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";
rename($oldname,$newname);
}

mlseim
10-26-2009, 07: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:


<?php

// Destination directory path.
$path="../photos/";

// 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
$file=$path.$filename;
imagepng($im,$file);

// clear memory
imagedestroy($im);

// end of loop

?>

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

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


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum