Jump to content

deleting files


php_novice2007

Recommended Posts

  • 2 weeks later...

Hi,

 

So far I've got something like this:

 

function doClose() {
    alert("here!");
    GUnload(); 
    window.location="deleteCreatedFiles.php?fname=<? echo $blah; ?>";
}
                       
<body onunload="doClose();">

 

And deleteCreatedFiles.php:

    session_start(); 
    if(session_is_registered('userid')){
      if (isset($_GET['fname'])) {
        try {
          $myFile = $_GET['fname'].".xml";
          unlink($myFile);
          $myFile = $_GET['fname']."velData.xml";
          unlink($myFile);
          if ($_SESSION['group']=="admin") {
            $URL="displayAdmin.php";
            header ("Location: $URL");
          } else {
            $URL="display.php";
            header ("Location: $URL");
          }
        } catch (Exception $e) {
          echo "Unable to delete file. <br>";
          if ($_SESSION['group']=="admin") {
            echo "<a href=MenuAdmin.php>Back to Menu</a>";
          } else {
            echo "<a href=Menu.php>Back to Menu</a>";
          }
        }
      } else {
           echo "This page require input from somewhere else.<br>";
           if ($_SESSION['group'] ==  "admin") {
              echo "<a href=MenuAdmin.php>Back to Menu</a>"; 
           } else {
              echo "<a href=Menu.php>Back to Menu</a>";
           }
      }
    } else {
      echo "You are not logged in.";
    }
?>

 

I've found that this code work if the user clicks on the Back button of the browser, it also works for the back button that I made on the page (these either goes back to displayAdmin.php or display.php) I guess it works because of the code I've got in deleteCreatedFiles.php after the unlink() lines.

 

But I want to be able to delete the files when the user clicks the refresh button as well as when the user closes the window. I know that doClose() is being called when the user clicks refresh since the alert poped up, but I'm not sure how to modify deleteCreatedFiles.php.

 

The alert does not pop up when I click on the close window cross... how can I achieve the file deletion..?

 

Thanks~!

Link to comment
Share on other sites

Hey,

 

Maybe this might help. On the page where you want to delete the files, add the following somewhere in the page (doesn't matter where):

 

<img src='delete.php' width='0' height='0' style='visibility:hidden;' />

 

Then substitute whatever your deletion script is called for 'delete.php'.

 

Not sure if this is what you're looking for... hope it helps...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.