CGI, header, and redirect

Discussion in 'Perl' started by FLUX (a l'Ircam), Jan 30, 2004.

  1. Hi Perl folk!

    I have the following problem :
    I want to upload a file (stored in a web server) to the browser, and then
    delete the file in the server. This file contains the results of a sound
    analysis/synthesis and is named XXX.zip with XXX the basename of the
    initial sound file...

    If I used: "redirect(-uri=>$UPLOAD_DIR/my_file.zip);"
    it would be OK, but then I can't delete the file after it is
    downloaded...

    So I did the following :
    <CODE>

    print header(-type=>'application/zip');
    open UPLOADFILE, "<$UPLOAD_DIR/$my_file.zip";
    binmode UPLOADFILE;
    while ( <UPLOADFILE> ){
    print ;
    }
    close UPLOADFILE;
    `rm -fr $UPLOAD_DIR/my_file.zip`;

    </CODE>

    But there is a big problem with that : when the user download the zip file
    it is named like the cgi script : for exemple "get_result.cgi" instead of
    "sound56.zip"

    Is there a way to force a name? Maybe using an option in the header?
    I read the CGI.pm perldoc and googled it, but I could'nt find anything of
    value...

    PS : sorry if you find this question stupid, but I'm quite new to Perl...

    Flux

    --
    "Pour moi la programmation est plus qu'un art applique important, c'est
    aussi une ambitieuse quete menee dans les trefonds de la connaissance"

    Grace Hopper, inventeur du compilateur
     
    FLUX (a l'Ircam), Jan 30, 2004
    #1
    1. Advertising

  2. Solution (was CGI, header, and redirect)

    > print header(-type=>'application/zip');
    > open UPLOADFILE, "<$UPLOAD_DIR/$my_file.zip";
    > binmode UPLOADFILE;
    > while ( <UPLOADFILE> ){
    > print ;
    > }
    > close UPLOADFILE;
    > `rm -fr $UPLOAD_DIR/my_file.zip`;
    >
    > But there is a big problem with that : when the user download the zip file
    > it is named like the cgi script : for exemple "get_result.cgi" instead of
    > "sound56.zip"
    >
    > Is there a way to force a name? Maybe using an option in the header?
    > I read the CGI.pm perldoc and googled it, but I could'nt find anything of
    > value...



    Well, I just found it! Sorry for the nuisance. Here is the solution :
    I had to use :
    ^^^^^^^^^^^^
    print header(-type=>"application/octet-stream", \
    -attachment=>"my_filezip");

    instead of :
    ^^^^^^^^^^
    print header(-type=>'application/zip');

    See you!

    Flux

    --
    "Pour moi la programmation est plus qu'un art applique important, c'est
    aussi une ambitieuse quete menee dans les trefonds de la connaissance"

    Grace Hopper, inventeur du compilateur
     
    FLUX (a l'Ircam), Jan 30, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=

    CGI and Redirect

    =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=, Feb 21, 2006, in forum: Python
    Replies:
    2
    Views:
    425
    Fredrik Lundh
    Feb 21, 2006
  2. mlt
    Replies:
    2
    Views:
    907
    Jean-Marc Bourguet
    Jan 31, 2009
  3. Sal
    Replies:
    1
    Views:
    1,003
  4. Haris Bogdanovic

    cgi.header redirect

    Haris Bogdanovic, May 6, 2008, in forum: Ruby
    Replies:
    3
    Views:
    134
    Albert Schlef
    May 11, 2008
  5. David Susco

    ruby cgi, add params and redirect

    David Susco, Sep 29, 2008, in forum: Ruby
    Replies:
    3
    Views:
    220
    David Susco
    Sep 30, 2008
Loading...

Share This Page