开发者

MIME Type Header not working. Browser Opening file instead

开发者 https://www.devze.com 2023-03-27 07:53 出处:网络
I am running a perl cgi script trying to open a \"save-as\" dialogue box to let the user download and save a particular file on their computer. Currently my code looks something like this:

I am running a perl cgi script trying to open a "save-as" dialogue box to let the user download and save a particular file on their computer. Currently my code looks something like this:

p开发者_StackOverflow社区rint "Content-Disposition: attachment; filename=$temp\n\n"; 
print "Content-Type: application/x-download\n"; 
print @fileStuff

I've scoured the internet and it seems that the MIME type headers are correct but they do not seem to be working though. The browser seems to be opening the file and displaying the contents instead. This is problematic as the file is quite large. I get the same result on chrome and firefox.

Thanks!

EDIT:

my $path = "/home/blabla/Desktop/";
my $temp = $fileList[3];
warn ($temp);
my @fileholder;
push (@fileholder, "<$path/$temp");

print "Content-Type:application/x-download\n"; 
print "Content-Disposition:attachment;filename=$temp\n\n";
print @fileholder


You've got two \n\n in your Content-disposition line. The second \n terminates the header block and starts the body block, so the Content-Type header actually becomes part of the body of the document. Remember that in HTTP, everything output is a header until a blank line is encountered, after which the body starts.

Swap the order of your two lines, or move the second \n to the Content-Type line and see what happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号