tags:

views:

93

answers:

1

hey guys, not sure how i should name the title of the post.

i'm having a submitbutton on my page that's creating a folder for me. as soon as i press it. the site AUTOMATICALLY refreshes. There's no script set in my document that says the page should refresh. it just happens when i submit anything, right?

if (isset($_POST['createDir'])) {   
    $dir = $_POST['dirname'];
    $targetfilename = PATH . '/' . $dir;
    if (!is_dir($targetfilename)) {
        mkdir($targetfilename);
        chmod($targetfilename, 0777);
    } else {
        echo "Folder exists!";
    }   
}

a bit further down in my script i have the same thing to delete files and folders.

if (isset($_POST['deleteBtn'])) {
    chmod(PATH, 0777);
    foreach ($_POST['deletefiles'] as $value) {
            unlink(PATH . '/' . $value);
    }
    echo "<META HTTP-EQUIV=Refresh CONTENT='0'>"; //doesn't work without it!
}

if i click the submitbutton to delete a folder the pages DON'T refresh. Even though the script works and the files get deleted. Where is difference between the script creating a folder and the other one to delete files. I actually don't really get it.

regards matt

+1  A: 

Ok, after our extended conversation in the comments, I think I can now safely say that this is what's going wrong. Considering that this is the order your code executes (based on http://cl.ly/1nUn):

  1. if the create-folder button was pressed, create the folder
  2. run through the directory and store all filepaths in a variable
  3. if the delete-folder/file button was pressed, remove the folder/file
  4. display the directory content retrieved in step 2.

In that case, the error is that the above step 2 and 3 should be switched! If you first list all the files, and then delete some, it will not be reflected in the output since that list as obtained just before deletion.

In general, you want to first handle any user command to create/delete/modify files and directories, and only at the last moment list the must up-to-date state of the filesystem.

catchmeifyoutry