Solved

block file

Posted on 2003-10-27
5
203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

21 Experts available now in Live!

Get 1:1 Help Now