Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fread error

Status
Not open for further replies.

soulman1

MIS
Aug 14, 2005
1
GB
hi guys


i have a problem with a php script ( a login scriptwhich uses a txt page for information ), i have tried everything to try and find a solution even looking in the tutorials bet to no avail


the error it keeps throwing up is

Warning: fread(): Length parameter must be greater than 0. in /home/souldude/public_html/login/admin/index.php on line 267

now i've checked the script

this is the line : $loadcontent = fread($fp, filesize($loadcontent));

and the full part of the script is here

<?php
$loadcontent = "../advanced_members/$u_name.txt";
if($save_file) {
$savecontent = stripslashes($savecontent);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
print '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>';
print "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>";

}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));

$lines = explode("\n", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a\n";
}
//index.php?userinfo=38 (aaaaa)
?>

any help in resolving this would be gratefull
I am new to php so any help would be grateful
thanks
 
You have this twice.
You don't need this anymore (the second one - before
$loadcontent = fread ($fp, filesize($loadcontent));

Because your variable was overwritten.

$fp = @fopen($loadcontent, "r");

Or if you want to do the same, you need to rename your filename string to:

$loadcontent_file = "../advanced_members/$u_name.txt";

And

change this:
$fp = @fopen($loadcontent_file, "r");
$loadcontent = fread($fp, filesize($loadcontent_file));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top