flock() Permission denied error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc

    flock() Permission denied error

    Hello,
    when using flock() I get a permission denied error:

    Warning: fopen("<filenam e>", "r+") - Permission denied in <pathtofile>
    on line 7

    I do this:

    $fileToOpen=sub str($PHP_SELF, strrpos($PHP_SE LF,"/")+1);
    $fileHandle=fop en($fileToOpen, 'r+') or die($php_erorms g);
    flock($fileHand le,LOCK_EX | LOCK_NB);
    $fileString=fre ad($fileHandle, filesize($fileT oOpen)) or
    die($php_erorms g);

    // ,,
    // procesing of filecontents
    // ,,

    rewind($fileHan dle);
    if(-1==fwrite($file Handle,$newFile )) {die($php_error msg);}
    ftruncate($file Handle, ftell($fileHand le)) or die($php_errorm sg);
    flock($fileHand le,LOCK_UN);
    fclose($fileHan dle);

    It seems to me that I incorrectly place the flock()'s but the manual
    suggest putting flock($fileHand le,LOCK_EX) after the fopen() and the
    flock($fileHand le,LOCK_UN) before the fclose()...

    Placing the flock($filehand le, LOCK_UN) just before the fclose()
    produces the same result...

    All I can do from that point on is to delete the file and use a new
    (copy of the unaffected) file...

    php4.1.2
    MacOSX 10.2

    Marc
Working...