[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] A couple of file uploading questions...




> I'm interested in knowing more about the details of this solution.
> I'm thinking of a case where if the form is successfully validated, it
> gets inserted or updated in a database. If it doesn't validate, I don't
> care about the attachments. How do you handle making sure the file names
> you choose don't collide, as well as deleting old attachment files for
> forms that were never completely validated and submitted? Using a cron
> script comes to mind.

Whether you care about the attachments or not, they get sent across with
the form.  If the attachments take a significant amount of time to send,
you don't want to have wasted that time just because a user forgot to fill
in a single field in the form.  (There's also the minor inconvenience of
having to re-enter the file in the file field.)  That's the case in my
application.  So the file always gets written to a staging area at the
outset, and gets moved to an archive area only if the form successfully
validated.  Part of the validation is to check that the file name (plus
path, which comes from other parts of the form) doesn't already exist.
If that happens, you have three choices:  the user is always right, so
automatically add a unique id to the filename, rename the physical file
and the .upld parameter in the CGI query, and continue; the user is
always wrong, so signal an error and either delete the file right then
or leave it for a cron job to clean up; or let the user choose which to
do, possibly including what to rename the new file if they want to
keep it.  (If the user simply wanted to edit an existing entry by
providing a new, improved file, then they should use the edit run mode
instead of the add run mode; file name collisions are not treated as
errors in the former.)  The staging area gets cleaned by a cron job.

-- Mike F.




---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.