Jump to content

Recommended Posts

here is my code to open/read an xml file before posting to it.

 

$file = "bb.xml";
$act = fopen($file, "r+");
$lock = flock($act, LOCK_EX);
$read = fread($act, filesize($file));

 

here is the error_log entry:

 

PHP Warning:  fread() [<a href='function.fread'>function.fread</a>]: Length parameter must be greater than 0 in go.php on line 37

 

can anyone help a newbie solve this problem?  :confused:

 

Well it probably has to do with the path, but not 100% sure (could also be due to the lock).

 

Why not just read it all in with file_get_contents instead before you lock it or get the filesize before you lock it. Either or should work.

This still produces the error:

 

$file = "bb.xml";
$size = filesize($file);
$act = fopen($file, "r+");
$lock = flock($act, LOCK_EX);
$read = fread($act, $size);

 

If it still produces the error, is at any point this file deleted?

do a var_dump on the $size variable. See if the size is coming out.

 

If not, set it to a manual size that it should never hit like (1024*1000) or something. That should cover you.  Or to read it, just do a file_get_contents before the fopen, then you do not have to worry about it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.