note 50637 modified in function.fread by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 Jan 2012 21:11:45 +0000 |
| Subject: | note 50637 modified in function.fread by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185439@lists.php.net to get a copy of this message | ||
To make the effects of the latest PHP version changes of the fread function even more explicit: the
new size limitation of fread -regardless of the filesize one specifies, in the example below 1024 *
1024- means that if one was simply reading the contents of a text file from a dynamic URL like so:
<?php
$dp = "http://www.example.com/filename.php";
$buffer = fopen($dp, 'r');
if (!$buffer)
{
echo("<P>Error: unable to load URL file into $buffer. Process
aborted.</P>");
exit();
}
$sp = fread($buffer, 1024*1024);
fclose($buffer);
highlight_string($sp);
?>
one should from now on use the file_get_contents function, as shown below, to avoid one's text
being truncated forcibly.
<?php
$dp = "http://www.example.com/filename.php";
if (!$dp)
{
echo("<P>Error: unable to load URL file into $dp. Process
aborted.</P>");
exit();
}
$sp = file_get_contents($dp);
highlight_string($sp);
?>
I thought it couldn't hurt to clarify this detail in order to save time for anyone else who is
in the same situation as I was tonight when my ISP abruptly upgraded to the latest version of PHP...
:(
Thank you to every previous contributor to this topic.
--was--
To make the effects of the latest PHP version changes of the fread function even more explicit: the
new size limitation of fread -regardless of the filesize one specifies, in the example below 1024 *
1024- means that if one was simply reading the contents of a text file from a dynamic URL like so:
<?
$dp = "http://www.whatever.com/filename.php";
$buffer = fopen($dp, 'r');
if (!$buffer)
{
echo("<P>Error: unable to load URL file into $buffer. Process
aborted.</P>");
exit();
}
$sp = fread($buffer, 1024*1024);
fclose($buffer);
highlight_string($sp);
?>
one should from now on use the file_get_contents function, as shown below, to avoid one's text
being truncated forcibly.
<?
$dp = "http://www.whatever.com/filename.php";
if (!$dp)
{
echo("<P>Error: unable to load URL file into $dp. Process
aborted.</P>");
exit();
}
$sp = file_get_contents($dp);
highlight_string($sp);
?>
I thought it couldn't hurt to clarify this detail in order to save time for anyone else who is
in the same situation as I was tonight when my ISP abruptly upgraded to the latest version of PHP...
:(
Thank you to every previous contributor to this topic.
http://php.net/manual/en/function.fread.php