Teh_Craze
asked on
Perl - content-type:application/??? Forcing Downloads -- URGENT
When setting the content type to application/mp3 how would I set the filename and file size?
In PHP it's just header("Content-Dispositio n: filename: $file");
But how would I do this in perl.
I've tried:
open(mp3, "./little-to-late.mp3");
print "Content-type:application/ mp3";
print "Content-Disposition: attachment; filename=little-to-late.mp 3";
foreach (<mp3>) {
print;
}
but it doesn't seem to be working, any ideas on how this might be accomplished?
In PHP it's just header("Content-Dispositio
But how would I do this in perl.
I've tried:
open(mp3, "./little-to-late.mp3");
print "Content-type:application/
print "Content-Disposition: attachment; filename=little-to-late.mp
foreach (<mp3>) {
print;
}
but it doesn't seem to be working, any ideas on how this might be accomplished?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AHK IT WORKS WHEN IN A DIFFERNT WINDOW. Crap.
Thanks. Your points.
Thanks. Your points.
what is your expected result?
ASKER
It's giving me a 0kb file.
ASKER
it should be putting out the actual file.
like www.alpha-vii.com/mp3/little-to-late.mp3
the script is just a download handler that I plan to develop further.
like www.alpha-vii.com/mp3/little-to-late.mp3
the script is just a download handler that I plan to develop further.
ASKER
Once again, error on my part. it's little-_too_-late. not little-_to_-late.mp3
ASKER
Just another question, how would I tell the browser how big the actual file is?
ah, glad you got it fixed. good luck with your handler. I would suggest that you use CGI.pm for perl CGI code.. it's full of good features and it's included standard. perldoc CGI for more info.
Also, this is an excellent free book on Perl (Not just for beginner's) that contains an entire chapter on CGI:
http://learn.perl.org/library/beginning_perl
Also, this is an excellent free book on Perl (Not just for beginner's) that contains an entire chapter on CGI:
http://learn.perl.org/library/beginning_perl
ASKER
Nevermind, got it. Content-length: $size.
Thanks.
Thanks.
Do you mean prior to download? (Like on a 'Download this: ' page?)
Just stat the file. stat() will return a list of values related to the file. The 7th list item (0 being the first) is the size in bytes.
Just stat the file. stat() will return a list of values related to the file. The 7th list item (0 being the first) is the size in bytes.
ASKER
Want to give me an example on stat()? Never used it before.
Sure, given that your filehandle is in 'MP3':
my $size = (stat(MP3))[7];
or:
my ($dev,$ino,$mode,$nlink,$u id,$gid,$r dev,$size, $atime,$mtime,$ctime,$blks ize,$block s)= stat($filename);
or:
my @stat_info = stat($filename);
Type:
perldoc -f stat
at your command line for an in depth description of everything.
This also works for any perl builtin function or module:
perldoc Module::Name
perldoc -f builtin_function
my $size = (stat(MP3))[7];
or:
my ($dev,$ino,$mode,$nlink,$u
or:
my @stat_info = stat($filename);
Type:
perldoc -f stat
at your command line for an in depth description of everything.
This also works for any perl builtin function or module:
perldoc Module::Name
perldoc -f builtin_function
ASKER
Here's the output.
www.alpha-vii.com/mp3/fixme.dll