jeudi 1 mars 2018

Javascript/PhP Deleting File when leabing the website

I am looking for a way to delete a unique file that is being generated in a specific folder. When the user leaves the page without completing the "task", the file should be deleted. The file naming is uniqe via uniqid()

I tried it with the following way:

<script>

    window.onbeforeunload = <?php unlink($_POST['localfile']) ?>;

</script>

But somehow this is not alway working. As example it is working when I am using the back button but when I put an other url in to my searchbar and go to the wanted destination as example google.com the file will not be deleted. How could I fix this issue or is there maybe an other way of solving this problem?




Aucun commentaire:

Enregistrer un commentaire