Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Creating dynamically named CGIs

by screamingeagle (Curate)
on Feb 13, 2002 at 06:06 UTC ( #145089=note: print w/replies, xml ) Need Help??

in reply to Creating dynamically named CGIs

something on these lines :
chdir($filepath); my $filesize = -s $filename; print "Content-disposition: attachment;filename=$filename\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/octet-stream\n\n"; open(READ,$filename) || die; while (<READ>) { print; } close(READ);
where filepath is the folder in which u store all the files which the users want to download (e.g. "/tmp") and the filename is the value passed along in the URL (or by the POST method)

Replies are listed 'Best First'.
Re: Re: Creating dynamically named CGIs
by ryan (Pilgrim) on Feb 13, 2002 at 07:16 UTC
    Thanks for the replies everyone, so far I have got it working to my satisfaction, but the browser has other ideas, I'm using CGI::Application so the sub in question (with hard coded parameters) is below:
    sub do_download { my $self = shift; my $post = $self->query(); my $fname = "/storage/surtron/cda/clients/ryan/new/surtron-020"; my $fsize = -s $fname; $self->header_props( -type => "application/octet-stream", -attachment => "", -Content_length => $fsize); open(READ,$fname) || die; my @fcontent = <READ>; close(READ); return "@fcontent"; }
    The above code correctly produces the following output
    Content-Disposition: attachment; filename="" content-length: 139124 Content-Type: application/octet-stream PK {rest of zip file}
    Evidently the browser is not honouring the Disposition header, I'm testing it will IE 6.0.2600.0000. Any further ideas?

    There is a MS support article on this for IE 5.5: FIX: "Content-Disposition: Attachment" Fails for Known Content Types (Q267991) HERE

    I just went for a drive to test IE 5.5 with the fix, it recognises it needs to download, then pops up 2 prompts, one for the name of the CGI and one for the name passed in the Disposition header, then it saves the file in some unknown format which winzip doesn't like. Hmmm is there any hope?

    Could the code I have provided possibly mangle the data in any way so as to cause it to be an invalid zip file? When I try to recover the zip file I can recover the first 2 files out of the 5 in the archive.

    More Updating:
    I just changed the code to a crude:
    my $filecat = `cat /blah/blah/whatever`; return $filecat;
    and now it all works :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://145089]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-12-16 00:14 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (446 votes). Check out past polls.