Link to home
Start Free TrialLog in
Avatar of Mario_castro
Mario_castro

asked on

block file

Hello

I need block a file while the user edit.

any ideas?

Thanks

Mario
ASKER CERTIFIED SOLUTION
Avatar of rstorey2079
rstorey2079

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mario_castro
Mario_castro

ASKER

and when verify that the file is lock?
After PHP opens the file using fopen, you can verify that you are the only one using it by calling flock().  If flock() returns false, that means that you could not obtain a lock on the file.

Here's the example:

<?php

$fp = fopen("/tmp/lock.txt", "w+");

if (flock($fp, LOCK_EX)) { // do an exclusive lock
    fwrite($fp, "Write something here\n");
    flock($fp, LOCK_UN); // release the lock
} else {
    echo "Couldn't lock the file !";
}

fclose($fp);

?>

Hope that answers your question.