note 51719 added to function.fopen
| From: | god_father52athotmail at osu1 dot php dot net | Date: | Fri, 08 Apr 2005 12:17:22 +0000 |
| Subject: | note 51719 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87699@lists.php.net to get a copy of this message | ||
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>";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.fopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51719
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51719&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51719&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51719&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51719&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51719&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51719&report=yes
Search -- http://master.php.net/manage/user-notes.php