use php to lock a directory / files access on LInux

Is it possible to write a small code to lock the file / directory on Linux with PHP ? Tks
AXISHKAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Why not use htaccess for this?
AXISHKAuthor Commented:
It is a part of a function on a PHP applications system....
Brian TaoSenior Business Solutions ConsultantCommented:
What do you mean by "lock"? Please give more details.  Do you want to lock the file from other users locally on the server? or to prevent being accessed from the Internet? or something else?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AXISHKAuthor Commented:
some html pages should be locked temporarily for multi-user access. Need to ensure those copies will not be overrided,... for any reason.

Tks
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Are you writing a CMS?  If that is the case, you can force a check in / check out.  If somebody wants a page, they click a button or link to get it. You mark a flag in the db that it is being edited and your php code prevents others from seeing any type of edit box.  Once the user "checks out" then others can edit.  I would put in some type of timer after x minutes to pop up and ask the user if they are still editing though.  If no response, release by updating the edit flag in the db.
AXISHKAuthor Commented:
Yes, but the files may be accessed through FTP, not such the PHP application... Tks
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
So are you talking about document management?

You can do the same thing.  Keep the files outside of your www folder.  Again, use form to call up the file.  Write to the database the time stamp it is checked out.  Then again when it is checked in.   Don't allow your code to call up a file if it is checked out.

I may be confused though because your question asked about using php.  If somebody is using ftp, I don't think there is a way to lock the file.  What I am suggesting is using php to mimic visually what ftp does except you are using the file system to call up a file from outside the www folder (so it can't be accessed directly).  Write to a database or text file noting the file is locked out when checked out.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan CraciunIT ConsultantCommented:
1. don't allow ftp access to root (to prevent overwrite by superuser)
2. once the file has been checked out, save the current attributes, then chown it to the current user, chmod 0644
3. once the user has finished editing the file, restore the previously saved attributes (owner and rights).

HTH,
Dan
AXISHKAuthor Commented:
tks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.