Jump to content

Recommended Posts

I just tried doing:

 

function deleteFile() {

    var myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");

    var file = myActiveXObject.GetFile("<? echo $xmlName; ?>");

    file.Delete();

}

 

and it doesn't recognise what an ActiveXObject is...

 

 

Link to comment
https://forums.phpfreaks.com/topic/61769-deleting-files/#findComment-307566
Share on other sites

like this without javascript really

<a href="deleteFiles.php?imageUrl=myJPG.jpg">delete image</a>

 

or with javascript

window.location="deleteFiles.php?imageUrl=myJPG.jpg";

 

 

then on your deleteFiles.php you just use a get

<?php
$_GET['imageUrl'];
?>

Link to comment
https://forums.phpfreaks.com/topic/61769-deleting-files/#findComment-308823
Share on other sites

  • 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
https://forums.phpfreaks.com/topic/61769-deleting-files/#findComment-315747
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
https://forums.phpfreaks.com/topic/61769-deleting-files/#findComment-317161
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.