S
S
st4lev4r2020-05-25 17:44:32
PHP
st4lev4r, 2020-05-25 17:44:32

How can I delete a user uploaded file after the client closes the page?

Testing locally on Open Panel Server: Apache 2.4 + PHP 7.0.
A POST request is generated with a file. The file is uploaded to the server and accessed by JS. Access is needed for the entire time the page is open.
I tried to figure out the sessions and register my handlers when closing - it didn’t work out. The code, of course, was removed in order to at least somehow work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
ChernovGV, 2020-05-25
@ChernovGV

  1. Let's say once every 5 minutes you send an AJAX request to the server.
  2. You remember the last time of this request (database, file, etc.)
  3. For example, you check by cron, if the request did not come for more than 5 minutes, then you can delete the file

But if for some reason the connection with the user breaks, the file will be deleted despite the fact that the user's tab is open. For example, if he puts the computer in sleep / air mode.

Q
qwermus, 2020-05-26
@qwermus

I would make a cron file that will start at night and delete files uploaded, for example, more than a day ago.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question