Hello
I need to delete a file on my server when the window is closed

I used the onUnload event to execute a javascript
but javascript can not delete file on the server
so I try to delete file with php (unlink($fichier)) and it works
but I don't know how to do it when the window is closed

Thanks

    Have the onunload event open a window which points to fileA with the file's name in GET or POST or SESSION or COOKIE or whatever.

    Have fileA call scriptA that deletes the file that is passed.

    Have fileA close with body onLOAD js event.

      hello

      can you help me with the code please because I'm not an expert

      thanks

        Have the onunload open another window (search for pop-up in this forum or google.com) named popup.php calling it by
        popup.php?filename=bleh

        inside popup.php

        <?php
        //do your stuff
        if (file_exists($_GET['filename']) //or some other way
                                                        //to test if its there
        unlink($_GET['filename']);
        
        ?>

        <body onload="window.close();"></body>

        or something like that.

          I've had some success with doing thing in an <iframe> which is invisible and has a negative z-index. this would avoid having to pop-open a new window, that might be disabled by newer browsers anyway. For example:

          create an cross-browser invisible style:
          .invisible {
          display: none;
          visibility: hidden;
          z-index: -100;
          position: absolute;
          top: 0px;
          left: 0px;
          }

          then the frame:
          <iframe id="ifrm" class="invisible"></iframe>

          then on unload do this in a js fcn:
          if (document.getElementById) var ifrm = document.getElementById("ifrm");
          else var
          ifrm = document.all.ifrm;
          _frm.src = "unload.php";

          I don't know what kind of stuff you're storing in that file, but it seems like you might just want to see if you could store it in a cooke, and then it would be easy to expire the cookie on unload.

          finapollo

            Thanks for your help

            I used this method and it works fine for me

            in my window with the close event I have this code
            .....
            ......
            function VraiClose()
            {
            window.location='applet_delete.php?fic_del=<?php echo $filename;?>';
            };
            ....
            ....
            <body onUnload="VraiClose()">

            and I have applet_delete.php
            <?PHP
            if (file_exists($fic_del))
            unlink($fic_del);
            ?>
            <html>
            <head>
            <SCRIPT LANGUAGE="JavaScript">
            function Close(fichier)
            {
            win=top;
            win.opener=top;
            win.close();
            }
            </SCRIPT>
            </head>
            <body onload='Close()' bgcolor="#FFFFFF">
            </body>
            </html>

            Thank you again

              Write a Reply...