Search code examples
phppythontemporary-files

Store file for duration of time on webpage


I need to set up a page that will let the user upload a file, modify the file with a script, and then serve the file back to the user.

I have the uploading and modifying parts down, but I don't know where to put the file. They are going to be in the area of 1 or 2mb, and I have very little space on my webhosting plan, so I want to get rid of the files as soon as possible. There's no reason for the files to exist any longer than after the users are given the option to download by their browser upon being redirected.

Is the only way to this with a cron job that checks the creation time of the files and deletes them if they're a certain age?

I'm working with python and PHP.

edit:

First the file is uploaded. Then the location of the file is sent back to the user. The javascript on the page redirects to the path of the file. The browser opens save file dialog, and they choose to save the file or cancel. If they cancel, I want to delete the file immediately. If they choose to save the file, I want to delete the file once their download has completed.


Solution

  • I don't know why I didn't think of it, but I was on an IRC for Python, discussing a completely unrelated issue, and someone asked why I didn't just serve the file. Exactly!

    I never needed to save the file, just to send it back to the user with the correct header. Problem solved!