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

I've got a perl script that I can hit like:
server.com/get.pl?&file=file.kml

And have it hand my web browser the file as if I downloaded a link (not plaster the file on the screen).

Except, when I try to do this with compressed files like Zip files or Kmz (google Earth zip files), the file gets plastered on my screen just like I opened up a text file.

I think that's the problem, that I'm treating a file like a text file when it's a zip and has different encodings perhaps. But, I don't know what those encodings are for being able to open the file and shoot it out to the user.
The output I'm actually trying for is a google earth kmz file, but it's the same as a zip file, just called kmz instead of zip. If I can get a zip to work, the kmz will work too.
Code below.. Pretty well stumped. Any help appreciated.
Thanks!
sub kmzLoader(){ my ($KmlLoaderFile)=@_; open (DEST, "<$KmlLoaderFile") || warn "kmlLoader:: Can't load fil +e"; my @dataBuff = <DEST>; close DEST; $zipData = join ("\r",@dataBuff); } sub outKmz(){ print <<"OUTZIP"; Content-Type: application/vnd.google-earth.kmz Content-Disposition: attachment; filename="$fileName" $zipData OUTZIP }

Replies are listed 'Best First'.
Re: Open Zip and send to user in http session
by timos (Beadle) on Mar 18, 2006 at 11:08 UTC
    Maybe you could use 'application/octet-stream' as Content-Type string?

    Regards,
    Timo
Re: Open Zip and send to user in http session
by holli (Abbot) on Mar 18, 2006 at 13:34 UTC
    If you are running this on a windows server/machine, you will have to use binmode on the filehandle.
    open (DEST, "<$KmlLoaderFile") || warn "kmlLoader:: Can't load file"; binmode(DEST); my @dataBuff = <DEST>;


    holli, /regexed monk/
      I tried both of these. I still get a corrupt zip file.
        SOLVED.
        http://perlmonks.com/?node_id=9155 I originally searched the archives for download file, but after searching for file download, this was the only response and it worked great. I think the difference is that rather than just opening the file in binary, I'm also outputing it in binary?
        thanks!