Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing temp files

Status
Not open for further replies.

vortmax

Technical User
Aug 1, 2006
46
US
This might seem like an easy question, but...

I'm running a script that dynamically generates a postscript file, saves it to a temp directory and then generates an HTML link to the file. So when you hit the go button, you get a link to download the file.

To allow for multiple users, I'm using a unique ID scheme, where the file name is assigned a random number, so that no two users are assigned the same file name at the same time. The problem with this, is that the files never are deleted or overwritten from the temp folder.

Is there an easy way to delete the temp file after the user leaves the page (navagates away or closes the window)? I tried using crontab to schedule a mass delete of the contents of the folder every day at midnight, but that's more of a workaround then a solution.
 
Hi

I think the scheduled deletion is the right solution.

Anyway, you can not know for sure when the visitor leaves or closes the browser window.

You could do an AJAX request to a CGI script in a [tt]window.onunload[/tt] event handler. But I call that a workaround. But if the visitor's market leader browser crashes, there will be no notification and the visitor probably will return for another copy and the application will have to generate it again.

And there will be misbehaving spam bots which can start the generation and certainly will not notify when leaving. Depending on your implementation, maybe legitimate search bots will do that.

And did not mentioned visitors with disabled JavaScript because this usually degrades the discussion towards flame.

So in a final, you still have to keep the scheduled deletion too. Then why implementing another ?

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top