Question

Here is my problem. I am trying to download a file using header. Here is my code:

$content_type = mime_content_type('uploads/MyBBIntegrator_v1.3.1.zip');
$file = 'uploads/MyBBIntegrator_v1.3.1.zip';
header("Cache-Control: public");
header('Content-type: application/octet-stream');
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="MyBBIntegrator_v1.3.1.zip');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile('uploads/MyBBIntegrator_v1.3.1.zip');

However, the only result of this is that the page displays the contents of the file (it is a text file) or a string of strange symbols if the file is image/zip/exe etc

What should I do to solve this problem?

Was it helpful?

Solution

First of all, mime_content_type() is deprecated, you should try another method to fetch the MIME value.

I have checked your code and it works fine on my server, and it works fine for me. You should check for INI directives which might block the download. Try a fresh install server.

Also, there should be no output generated by the script before the snippet you put into your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top