note 51719 deleted from function.fopen by nlopess
| From: | nlopess@php.net | Date: | Fri, 08 Apr 2005 16:28:40 +0000 |
| Subject: | note 51719 deleted from function.fopen by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87716@lists.php.net to get a copy of this message | ||
Note Submitter: god_father52 at hotmail
Reason: useless
----
a function to grab remote files from the web, which returns the anchor tag of the downloaded file.
<?php
//how to use it..
echo getRemoteFile("http://www.google.com/intl/en/images/logo.gif");
//the function itself
function getRemoteFile($remoteFile) {
$parsedURI = parse_url($remoteFile);
$fileName = substr($parsedURI['path'], strrpos($parsedURI['path'],
'/') + 1);
if (!$remote = fopen($remoteFile, 'r')){
echo "Unable to open file the remote file: ".$remoteFile;
exit;
}
if (!$local = fopen($fileName, 'w')){
echo "Unable to open file the local file: ".$fileName;
fclose($remote);
exit;
}
$data = "";
while (!feof($remote))
{
$data = fread($remote, 8192);
fwrite($local, $data);
}
fclose($remote);
fclose($local);
return "<a href=\"$fileName\">$fileName</a>";
}
?>