treznik
treznik

Reputation: 8124

PHP file download header

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 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!

Upvotes: 0

Views: 1446

Answers (1)

St. John Johnson
St. John Johnson

Reputation: 6660

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));

Upvotes: 4

Related Questions