Page 1 of 1

copy image from remote server to hard drive

Posted: Tue Mar 29, 2011 4:23 pm
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');
?>