copy image from remote server to hard drive

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
RCstp
Forum Newbie
Posts: 6
Joined: Fri Mar 25, 2011 1:09 pm

copy image from remote server to hard drive

Post by RCstp »

I am trying to use the code below or any code if you have different ideas, to copy an image from a remote server and save the image either on my hard drive, or, on a server that I have access to that has a folder with permissions set at 777 so I should be able to write/save to that server. The code below runs without error messages but doesn't do anything.

Code: Select all

<?php
function save_image($inPath,$outPath) 
{ //Download images from remote server     
$in=    fopen($inPath, "rb");
$out=   fopen($outPath, "wb"); 
while ($chunk = fread($in,8192))
{         
fwrite($out, $chunk, 8192);     
}
fclose($in);
fclose($out); }
save_image('http://altatechsolutions.com/test/images/bad-display220x174.jpg','c:\data\image.jpg');
?>
Post Reply