I have an issue with my dailyreport.php page. Here is the link and the error I am getting. I am looking at my code and see if there is an issue with it.
http://www.chucksweather.com/dailyreport.php
Warning: fread() [function.fread]: Length parameter must be greater than 0 in /virtual/users/e14497-14796/web/dailyreport.php on line 10
Thanks,
Chuck
There is not enough information to help much…
The error is telling you that the problem is with the fread() function on line 10 of your dailyreport.php script.
It is saying that the length parameter can’t be 0. It must be higher.
fread function:
`string fread ( resource $handle , int $length )`
Can’t do much more than that without knowing what the script looks like and perhaps what it is trying to read.
Here is my code for that page.
<?php
$page_title = "Daily NOAA Report, Chucks Weather Station";
$keywords = "Daily NOAA Report, Chucks Weather Station";
$filename = "dailynoaareport.htm";
$handle = fopen($filename, "r");
//Read the contents of the file
$contents = fread($handle, filesize($filename));
fclose($handle);
//Trim everything after the initial body tag
$list = split("</HEAD>", $contents, 2);
$contents = $list[1];
//Trim the ending body tag
$list = split("</body>", $contents, 2);
$contents = $list[1];
require("testtags.php");
//Display the remaining contents
//
//include header here
include ('header2.php');
echo $contents;
//include footer here
?>
</body>
</html>
Chuck
Are you certain that $filename really is there?
Maybe test the value of $handle, or test the result of file_exists( $filename )?
Yes it has worked in the past. I have not checked it in a few days. The only thing I have done in the past few days was update WD but the dailynoaareport.htm works just fine.
Chuck
The warning message seems to indicate that filesize($filename) is returning a value of zero, i.e. either an error or a zero byte file - hence my earlier suggestion.
The filename which is dailynoaareport.htm is working. Here is the link.
http://www.chucksweather.com/dailynoaareport.htm
Chuck
You should use a loop instead of filesize…
Such like:
` $filename = “dailynoaareport.htm”;
$handle = fopen($filename, “r”);
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
`
This will get the whole file in chunks of 8192. You really should be checking to see if $handle contains anything. if the file is not there or there is an error, $handle will = FALSE…
But if you use the code above, if the file doesn’t exist, you will just get a blank $contents variable.
filesize doesn’t work for all objects.
It is working this morning. How would you check and see if $handle is working?
Chuck
Compare it to FALSE, and branch accordingly, e.g.
$handle = fopen($filename, "r");
if ( FALSE != $handle )
{
// We seem to have a good $handle, so proceed...
}
else
{
// Something is wrong...
}