Results 1 to 3 of 3

Thread: Title of a Perl CGI script

  1. #1
    Join Date
    Nov 2008
    Posts
    1,054

    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 (filedl.pl). 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:

    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

  2. #2
    Join Date
    May 2008
    Posts
    945

    Re: Title of a Perl CGI script

    To do this, usually I send the following HTTP header:
    Code:
    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.

  3. #3
    Join Date
    Feb 2008
    Posts
    194

    Re: Title of a Perl CGI script

    in the header, add this:
    Code:
    print $cgi->header("Content-Disposition: attachment; filename=nameofyourfile" );

Similar Threads

  1. How to run Perl script on Mozilla Firefox?
    By Grayson in forum Software Development
    Replies: 5
    Last Post: 02-11-2011, 02:35 PM
  2. Firefox problem with perl script
    By Gajendra1 in forum Software Development
    Replies: 6
    Last Post: 09-09-2010, 04:44 PM
  3. How to call perl script from Python?
    By Jhonwho in forum Software Development
    Replies: 3
    Last Post: 23-07-2009, 09:59 PM
  4. Is it possible to execute Perl script within another script?
    By RasMus in forum Software Development
    Replies: 2
    Last Post: 21-07-2009, 10:57 PM
  5. Need Perl script to execute from another.
    By beelow in forum Software Development
    Replies: 2
    Last Post: 20-06-2009, 09:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,453,511.59736 seconds with 17 queries