|
Posted by d on 02/02/06 18:43
<rendl42@gmail.com> wrote in message
news:1138880313.657493.280900@o13g2000cwo.googlegroups.com...
> 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
You're inter-changing $myfile, $myFile and $my_file - that might not help
the situation ;)
Navigation:
[Reply to this message]
|