PHP code to Save a file to local domain by just using its URL
Posted On at by milanIf you have been given a URL of a document like following
http://www.anydomain.com/anyfolder/thefile.doc
then by using a PHP script saving this to your own domain will be very easy and here goes the code to do that
// Download the given file to local inside the domain
$remoteFileContents=file_get_contents("http://www.anydomain.com/anyfolder/thefile.doc");
// Variable $localFilePath should contain path where u want to save file without slash at end.
// Variable $localFileName should contain the local file name to be given
$newFileHandle = fopen($localFilePath."/".$localFileName, "w");
fwrite($newFileHandle, $remoteFileContents);
fclose($newFileHandle);
?>