JohnB has asked for the wisdom of the Perl Monks concerning the following question:

When uploading files with the CGI.PM module how do I specify the default file extension when the user clicks on the browse button. I am using ActivePerl on Windows 98 with a Netscape browser.

This code will produce a file upload field on a form with a browse button:

print start_multipart_form, filefield(-name=>'upload',-size=>60),br, submit(-label=>'Upload File'), end_form;

When the user clicks on the browse button a file upload window opens with the default file extension set to HTML. I would like to change the default file extension to something else.

I couldn't find the answer in Lincoln Stein's book on CGI programming and I also tried using super search.

Replies are listed 'Best First'.
Re: Set File Upload Extension With CGI.PM
by chromatic (Archbishop) on Mar 23, 2001 at 00:42 UTC
    The closest you will get is using the 'accept' attribute. It takes a comma-separated list of MIME types, and the web browser has to support this attribute to constrain the results to the appropriate types.

    print start_multipart_form, filefield(-name => 'upload', -size => 60, -accept => 'image/*',), br, submit(-label => 'Upload File'), end_form;
    The only other possibility is that a client-side scripting language or componenet (JavaScript, applet, ActiveX control) will let you access the filetype filter. I don't find that likely, but web browsers do some spectacularly useless things that, occasionally, come in handy.