By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

flock() Permission denied error

P: n/a
when using flock() I get a permission denied error:

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

I do this:

$fileToOpen=substr($PHP_SELF, strrpos($PHP_SELF,"/")+1);
$fileHandle=fopen($fileToOpen, 'r+') or die($php_erormsg);
flock($fileHandle,LOCK_EX | LOCK_NB);
$fileString=fread($fileHandle, filesize($fileToOpen)) or

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

if(-1==fwrite($fileHandle,$newFile)) {die($php_errormsg);}
ftruncate($fileHandle, ftell($fileHandle)) or die($php_errormsg);

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

Placing the flock($filehandle, 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...

MacOSX 10.2

Jul 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.