in reply to Re^2: Full path for uploaded file
in thread Full path for uploaded file
I wanted to upload a file and process it, and then dynamically create a web page that would allow a user to upload the same file again and process it in some other way.
Um, what? That sounds like a broken design. Why the two uploads?
I think you should post some more details. What kind of file do your users upload? What happens during the processing phases?
I could just store the file on the server the first time it was uploaded and use it again in the second processing phase, but I don't want to keep a permanent copy of the file on the server, and I don't see any way of ensuring the file gets deleted (the user might decide not to initiate the second processing phase).
Ask the user before uploading starts. Maybe a simple checkbox "run phase 2" is sufficient. Then run either only phase 1 or both phases, depending on the checkbox.
When you use CGI, CGI.pm will usually take care of cleaning up. Sometimes, when your CGI script crashes, CGI will not clean up, and uploaded files will pile up in some temp directory. The private tempfiles pragma is very helpful when running on systems derived from Unix (Linux, *BSD, ...): It unlinks the temp file, but keeps an open handle for it. The file content is preserved, but as soon as the handle is closed, the operating system will free the disk space occupied by the file. The only disadvantage may be that the file no longer has a name that you could pass to external programs. But you can inherit the handle to an external program, or you can use the handle as STDIN for an external program.
I thought of using <body onUnLoad="some_script"> but I don't think this works if the user just shuts down the browser instead of navigating away from the page.
Correct. onUnload is not reliable. Think about using a session, delete the file after the session has expired.
I also tried using Javascript which gets called when the form's submit button is clicked, but this doesn't work either.
Define "does not work". And how is submitting a form related to deleting a file on the server?
I guess I could use a cron job to get rid of the file on the server.
Yes, but not really needed. You can simply check if you need to clean up during some later request. Either search for expired sessions and clean up their temp files, or simply delete all temp files that are too old to be in use (e.g. older than one day).
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Full path for uploaded file
by JanetSilk (Initiate) on Apr 15, 2011 at 14:58 UTC |