|
Posted by rendl42 on 02/02/06 13:38
Hey all,
I'm a relative newbie to PHP, and am getting some strange results with
the fread() function with PHP (win32) 5.1.2. Here is some code:
<?php
echo $_SERVER['PHP_SELF']."<br>";
echo $_SERVER['DOCUMENT_ROOT'];
$myFile = $_SERVER['DOCUMENT_ROOT']."/Dave/blah.txt";
echo $myfile."<br>";
if (file_exists($myFile)) {
$fh = fopen($myFile, 'r');
// $theData = fread($fh, filesize($my_file));
$theData = fread($fh, 282);
fclose($fh);
echo $theData;
} else {
echo "<br>"." The file";
echo $_SERVER['DOCUMENT_ROOT'];
echo "$myFile does not exist";
}
?>
Now when I run the script using the commented out line for setting
$theData variable, i get a file cannot be 0 bytes message (see error
message at bottom). The file however is not empty. When I replace that
commented line with the line below, I am able to echo $theData
successfuly. I have heard that perhaps there is a bug with fread() in
5.1.x (not sure which rev), but this is causing major pain.
Am I doing something wrong? If this is a bug, is there a simple
alternate I can use?
Thanks heaps!
Warning: fread() [function.fread]: Length parameter must be greater
than 0 in C:\server\wamp\htdocs\dodger\blah.php on line 9
[Back to original message]
|