I'm trying to copy a file from a remote location and the file copies across but has a size of 0kb. Can anyone suggest why this is happening?
Code:
<?php
function copyFile($url,$dirname)
{
@$file = fopen ($url, "rb");
if (!$file)
{
echo"<font color=red>Failed to copy $url!</font><br/>";
return false;
}
else
{
$filename = basename($url);
$fc = fopen($dirname."$filename", "wb");
while (!feof ($file))
{
$line = fread ($file, 1028);
fwrite($fc,$line);
}
fclose($fc);
echo "<font color=blue>File $url saved to PC!</font><br/>";
return true;
}
}
?>
<?php
$filedir=$_SERVER['DOCUMENT_ROOT']."/include/";
copyFile("http://remote location.co.uk/include/file.php",$filedir);
?>
Comment