note 36263 added to function.file-get-contents
| From: | webmaster at ragnarokonline dot de | Date: | Thu, 02 Oct 2003 19:00:48 +0000 |
| Subject: | note 36263 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57625@lists.php.net to get a copy of this message | ||
Users of PHP4 < 4.3.0 can use the following:
It is binary safe and it can be used for external files.
<?php
if (!function_exists("file_get_contents")) {
function file_get_contents($filename, $use_include_path = 0) {
$data = ""; // just to be safe. Dunno, if this is really needed
$file = @fopen($filename, "rb", $use_include_path);
if ($file) {
while (!feof($file)) $data .= fread($file, 1024);
fclose($file);
}
return $data;
}
}
?>
btw: If anyone knows about a decent way to tell the difference between local and external files, he
may feel free to alter this to use filesize instead of the loop or eMail a suggestion to me. :)
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36263
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36263&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36263&report=yes