开发者

PHP file download header

开发者 https://www.devze.com 2022-12-23 12:31 出处:网络
I have developed a small download system in PHP, where files are downloaded through a proxy file. When I had to do this before, I just redirected by changing the location header; which is not what I w

I have developed a small download system in PHP, where files are downloaded through a proxy file. When I had to do this before, I just redirected by changing the location header; which is not what I want to do now.

So, obviously, the first issue that appeared is what kind of header must I set. First of all, Content-Disposition is set as "attachment", so this is good, but I can't seem to get around Content-Type. I need to set it to fit all开发者_StackOverflow社区 possible files that might be downloaded through this system. I don't know how to detect the file header automatically, and I'm trying to aviod a GIANT switch. What are my options?

Thanks!


There was an old function mime_content_type that would provide the value for you. It has been replaced with Fileinfo.

 $finfo = finfo_open(FILEINFO_MIME);
 header("Content-Type: ".finfo_file($finfo, $filename));
0

精彩评论

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