Solved

block file

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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.

809 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