PDA

View Full Version : Locking files and fclose


Justin
01-21-2000, 04:10 PM
Unfortunately it does remove the lock. What you might want to do is create a temporary file for use, using a unique name each time. A good way to do this would be via Apache's Unique ID. From PHP, simply use $UNIQUE_ID...

So you could open the original file (if necessary), read in whatever data you need, make whatever changes are needed, then write the file out to the temp file ($fp = fopen ("$UNIQUE_ID.txt", "w")) and use that.

Hope this helps point you in the right direction.

------------------
Justin Nelson
FutureQuest Support

Gurk
01-22-2000, 01:42 AM
I was wondering does fclose removes
a lock on a file? (Somebody told me)
Cause I want to do this:
lock file --> write to file --> close file
-> send file --> remove file.
But if fclose removes the lock somebody should be able to write to the file between close file and send file... so this could send a file with the wrong content. Any solution to this??? I can't put sendfile before close file because nothing will be written to the file if I do that.
I did this:
$fp = fopen($filename, "w");
flock($fp,2);
fwrite( $fp, $inhoud);
fclose($fp);
mailfile();
unlink($filename);

<!-- NO_AUTO_LINK -->