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

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





> I'm writing a CGI::App right now that will accept a file upload.  I'm
> trying to use uploadInfo->{Content-Type} from CGI to get the MIME type
> of a file, but it gives me an undefined hash reference error.  Any
> ideas?

If that's exactly what you're doing in the script, then your syntax isn't
correct.  According to the CGI perldoc:

  $filename = $query->param('uploaded_file');
  $type = $query->uploadInfo($filename)->{'Content-Type'};

> Also, is there a way to set the default entry in a File form input?  I
> want to fill in the name of the file if a user has already attached a
> document instead of presenting a blank field.

No; it would be insecure to let the script pass back a file name be
uploaded.  Conceivably, a script could grab any file from the browsing
host that it wants.

To get around this, after a successful file upload, I've added a CGI
parameter with the same name as the uploaded file field, but with '.upld'
appended; the value is the uploaded file name.  This gets appended to the
display of the form's filefield, so the user knows that the file has been
successfully uploaded.  My form validation method checks for the .upld
field, and if it matches a file uploaded to the server, it accepts an
otherwise empty file upload field.

-- 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.