Support the ongoing development of Laravel.io →
Session Views Forms

Hello,

I am uploading files using Dropzone, and save them after the upload has been performed (first step being the upload, second step is saving, when user clicks the Save button). All works fine.

The problem I am having is when user clicks Cancel, or simply navigates away from the page. I end up with a file or more uploaded in a temp folder - and I am trying to delete them (since the user has cancelled or has navigated away).

I wrote a route and a controller that deletes all the files from the temp folder, but I cannot seem to attach that to detecting when the user navigates away.

I am aware that this might be a JavaScript related issue - but I hope that someone else has been down this road before?

This is how I am trying to detect navigation away, and route assignement:

<script type="text/javascript">
  window.onbeforeunload = function() {
    document.location.href="{{ HTML::linkRoute('dz-cleanup') }}";
  }
</script>

However that is not working. It "strips" all my CSS styling and redirection never happens. However I am not convinced that this is the best way to do this (even if it worked, because of the redirection).

What would be the best approach to remove the uploaded (abandoned) files when users navigates away? I would appreciate some help.

Thanks,

Gabriel.

Laravel 5.2

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gabriel gabriel Joined 7 May 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.