PHP Rename Permission Denied - Error Handlng

Posted on 2007-08-12
Last Modified: 2013-11-05
My website maintains a database along with a set of folders on my server.  The Syncronization between these is working fine.  By this I mean if you add a record to the table a folder is created with the same name, if you rename the record the folder is renamed to the new name etc etc.

The problem i am having is that becuase we run a Windows 2003 server and remote desktop onto it to do various other file management tasks to the contents within these folders created by the website you can provoke a Permission Denied error on the website by accidently having a file open within a folder that PHP wishes to rename!

I understand that this is what should happen as the results are the same within Windows but instead of my website just keeling over with an error message i would like to pop up a message saying "Folder in use : rename not possible, try again later...." or something along those lines?

I have tried :

if (!rename($old_folder, $new_folder)) .....

But this does not work...

Is there another way around this?
Question by:Sailo100
    LVL 6

    Assisted Solution

    you could try:

    if(FALSE === rename($old_folder,$new_folder))
    // do something if rename failed
    echo "Folder in use : rename not possible, try again later....";

    Author Comment

    What does 3 equal signs mean?

    Author Comment

    This does not appear to work....  I still get permission denied?
    LVL 15

    Accepted Solution

    add a @ to rename call in the sample above to suppress the error message:


    === in PHP means "equal and the type is the same". For example:

    (FALSE == 0 ) is TRUE
    (FALSE === 0) is FALSE


    Author Comment

    Perfect thanks guys!  I've always wanted to know what @ was used for :-)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    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…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now