note 36263 rejected from function.file-get-contents by didou
| From: | didou@php.net | Date: | Mon, 20 Oct 2003 07:28:43 +0000 |
| Subject: | note 36263 rejected from function.file-get-contents by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58919@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@ragnarokonline.de
----
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. :)