You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Scott Chapman <sc...@mischko.com> on 2002/05/18 01:09:19 UTC

Sending zip file to browser

I have a <A HREF link that calls a script on the server. The script ends up 
with redirecting the customers browser to the zip file it creates.  I want the 
script to send the zip file instead of redirecting the user to the zip file (and 
potentially losing the form changes the link is on).

Is there an easy way to use EmbPerl to send the zip file?

Thanks!
Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Sending zip file to browser

Posted by Andrew O'Brien <an...@switchonline.com.au>.
On Mon, May 20, 2002 at 08:18:26AM -0700, Scott Chapman wrote:
> Gerald,
> Thanks for the followup.  I have two questions:
> 
> 1) By extra space in the file, you mean outside the [- -] embperl
> constructs right?  (This can't be there because it will be sent to
> the browser which will cause problems, right?)

Yes, extra space outside these blocks is bad.

> 2) Don't you have to do something fancy with the http output headers?  How 
> do I tell the browser that a zip file is coming?

Something like:

[-
  $http_headers_out{'Content-Type'} = "application/octet-stream";
  $http_headers_out{'Content-Length'} = $filesize; # optional
  $http_headers_out{'Content-Disposition'}
    = "attachment; filename=$filename";
  print OUT stuff while get_stuff_from_file; -]

I can't remember if embperl automatically sets the content-length
header so you may not need that.

If you are using embperl object depending on how you build your pages
you may have extraneous spaces in the building blocks of your page
output execute sequence.

I usually create a subdirectory somewhere and have the most simple
base.epl possible (with no extra spaces):

[- $req = shift; #maybe do other stuff here# Execute('*'); -]

And then have the above snippet as download.epl or whatever. That way
you can place all space-sensitive epl files in this subdirectory.

> > > I have a <A HREF link that calls a script on the server. The script ends
> > up
> > > with redirecting the customers browser to the zip file it creates.  I want
> > the
> > > script to send the zip file instead of redirecting the user to the zip
> > file (and
> > > potentially losing the form changes the link is on).
> > >
> > > Is there an easy way to use EmbPerl to send the zip file?
> > >
> > 
> > That the same like for any other binary file:
> > 
> > [-
> > $escmode = 0 ;
> > open FH, "filename.zip" ;
> > binmode FH ; # only on windows
> > while (read(FH, $buffer, 32768))
> >                 {
> >                 print OUT $buffer ;
> >                 }
> > close FH;
> > -]
> > 
> > Make sure you don't have any extra spaces/newlines in the page. You could do
> > the same with a Apache::Reigstry script to avoid problems with extra space
> > in the file
> > 
> > Gerald
> > 
> > 
> > -------------------------------------------------------------
> > Gerald Richter    ecos electronic communication services gmbh
> > Internetconnect * Webserver/-design/-datenbanken * Consulting
> > 
> > Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
> > E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
> > WWW:        http://www.ecos.de      Fax:      +49 6133 925152
> > -------------------------------------------------------------
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > For additional commands, e-mail: embperl-help@perl.apache.org
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 

-- 
 Andrew O'Brien
 Senior Engineer                       email: andrewo@switchonline.com.au.
 Switch Online Group Pty Limited       phone: +61 2 9299 1133
 ABN 89 092 286 327                    fax:   +61 2 9299 1134

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Sending zip file to browser

Posted by Wim Kerkhoff <wi...@nyetwork.org>.
See:

http://perl.apache.org/embperl/Faq.pod.3.html#How_can_I_customise_the_header
_t

You'll probably need to send a content type of application/zip.

Regarding the spaces, basically make the opening [- bracket be the very
first character in your Embperl file, and the closing -] be the last
character... otherwise the browser will see a .zip file that starts with an
extra space. If there are extra spaces at either the beginning or end of a
zip, and unzipper may have problems unzipping it. Whitespace withing the
[- -] doesn't matter, since it's just perl code and not sent to the browser.

-----Original Message-----
From: Scott Chapman [mailto:scott_list@mischko.com]
Sent: Monday, May 20, 2002 8:18 AM
To: Gerald Richter
Cc: embperl@perl.apache.org
Subject: Re: Sending zip file to browser


Gerald,
Thanks for the followup.  I have two questions:

1) By extra space in the file, you mean outside the [- -] embperl constructs
right?  (This can't be there because it will be sent to the browser which
will
cause problems, right?)

2) Don't you have to do something fancy with the http output headers?  How
do I tell the browser that a zip file is coming?



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Sending zip file to browser

Posted by Scott Chapman <sc...@mischko.com>.
Gerald,
Thanks for the followup.  I have two questions:

1) By extra space in the file, you mean outside the [- -] embperl constructs 
right?  (This can't be there because it will be sent to the browser which will 
cause problems, right?)

2) Don't you have to do something fancy with the http output headers?  How 
do I tell the browser that a zip file is coming?

Scott

On 18 May 2002 at 13:17, Gerald Richter wrote:

> 
> 
> > I have a <A HREF link that calls a script on the server. The script ends
> up
> > with redirecting the customers browser to the zip file it creates.  I want
> the
> > script to send the zip file instead of redirecting the user to the zip
> file (and
> > potentially losing the form changes the link is on).
> >
> > Is there an easy way to use EmbPerl to send the zip file?
> >
> 
> That the same like for any other binary file:
> 
> [-
> $escmode = 0 ;
> open FH, "filename.zip" ;
> binmode FH ; # only on windows
> while (read(FH, $buffer, 32768))
>                 {
>                 print OUT $buffer ;
>                 }
> close FH;
> -]
> 
> Make sure you don't have any extra spaces/newlines in the page. You could do
> the same with a Apache::Reigstry script to avoid problems with extra space
> in the file
> 
> Gerald
> 
> 
> -------------------------------------------------------------
> Gerald Richter    ecos electronic communication services gmbh
> Internetconnect * Webserver/-design/-datenbanken * Consulting
> 
> Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
> E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
> WWW:        http://www.ecos.de      Fax:      +49 6133 925152
> -------------------------------------------------------------
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Sending zip file to browser

Posted by Gerald Richter <ri...@ecos.de>.

> I have a <A HREF link that calls a script on the server. The script ends
up
> with redirecting the customers browser to the zip file it creates.  I want
the
> script to send the zip file instead of redirecting the user to the zip
file (and
> potentially losing the form changes the link is on).
>
> Is there an easy way to use EmbPerl to send the zip file?
>

That the same like for any other binary file:

[-
$escmode = 0 ;
open FH, "filename.zip" ;
binmode FH ; # only on windows
while (read(FH, $buffer, 32768))
                {
                print OUT $buffer ;
                }
close FH;
-]

Make sure you don't have any extra spaces/newlines in the page. You could do
the same with a Apache::Reigstry script to avoid problems with extra space
in the file

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org