Forum OpenACS Q&A: Retrieving MIME type of uploads

Collapse
Posted by Guan Yang on
ns_guesstype does a lowsy job. Is there any way of retrieving the
browser provided MIME type? This is analogous to PHP's
$_FILES['userfile']['type'].
Collapse
Posted by Don Baccus on
Yes, there is. If you're using 4.x CVS take a look at packages/acs-templating/tcl/file-procs.tcl. This is a new file type I added to the form handling code recently (it's not in the 4.5 release tarball). It's easy to use from ad_form and that's the recommended way to do it though examples are lacking. It's straightforward, though, you use the widget like this:
ad_form -form {
   {upload_file:file    {label "Enter a filename or use the browse button"}}
} -on_submit {
   set filename [template::util::file::get_property filename $upload_file]
   set tmp_filename [template::util::file::get_property tmp_filename $upload_file]
   set mime_type [template::util::file::getproperty mime_type $upload_file]
}
Filename is the filename entered by the user (the filename on their computer), tmp_filename is the path to the tempfile where AOLserver dumped the file, mime_type the mime type sent by the browser.