TechArena Community

TechArena Community (
-   Software Development (
-   -   Title of a Perl CGI script (

!const 26-03-2009 11:40 PM

Title of a Perl CGI script
I wrote a small Perl script that can download an existing file on the server. Everything works fine except that the file download has systematically filename perl ( Someone knows how to ensure that the file name to the proposed registration of the original file, not the perl script? I tried to add the head tag with title, but as can be expected, the mime type is automatically in text and binary file content is displayed in the browser, instead of being proposed to recording.

Here is an extract from the script code:


# Create the CGI
my $cgi = new CGI;
my $file = $cgi -> param ("file");
# Type MIME
my $mimetype = &get_mime_type($file);
# HTML Headers
print $cgi->header('Content-type: $mimetype; charset=utf-8');
open(FILE, "<$file" ) or die "Cannot open $file";
my @filedata = <FILE>;
close (FILE) or die "Cannot close $file";
print @filedata

Lemog 26-03-2009 11:42 PM

Re: Title of a Perl CGI script
To do this, usually I send the following HTTP header:

Content-Disposition: inline; filename="%s"; size=%d
Content-Length: %d
Content-Type: application/binary

<contents of file>

Where you replace %d with size in bytes of the file and %s the file name.

But in general it gets stuck with unicode characters >127. If you have this kind of character, will probably have to go through RewriteRule.

Ashok.M 26-03-2009 11:43 PM

Re: Title of a Perl CGI script
in the header, add this:

print $cgi->header("Content-Disposition: attachment; filename=nameofyourfile" );

All times are GMT +5.5. The time now is 05:49 PM.