Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Full path for uploaded file

by afoken (Chancellor)
on Apr 14, 2011 at 09:23 UTC ( [id://899395]=note: print w/replies, xml ) Need Help??


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

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^4: Full path for uploaded file
by JanetSilk (Initiate) on Apr 15, 2011 at 14:58 UTC

    Thanks again Alexander. The uploaded file contains genealogy data in the Gedcom format (plain text). The first processing phase generates a list of people and presents it to the requester as a table - one row per person. At the end of each row is a button which, if clicked, will do the second processing phase for that person. Running phase 2 for every person generated in phase 1 would take a long time and be wasteful - I would expect users to want to do phase 2 for only a few people (possibly zero).

    Javascript is unable to extract the full path name from the form data - that's what I meant by "does not work".

    Thanks for the tip about private tempfiles. I'll also look into sessions, which I've not used before.

    Regards, J.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://899395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found