Solved

block file

Posted on 2003-10-27
5
202 Views
Last Modified: 2006-11-17
Hello

I need block a file while the user edit.

any ideas?

Thanks

Mario
0
Comment
Question by:Mario_castro
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
rstorey2079 earned 50 total points
ID: 9629176
Try using flock() function.  There is an example here: http://us2.php.net/manual/en/function.flock.php
0
 

Author Comment

by:Mario_castro
ID: 9629713
and when verify that the file is lock?
0
 
LVL 1

Expert Comment

by:rstorey2079
ID: 9629761
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now