\nThanks!
\n","author":{"@type":"Person","name":"user2824073"},"upvoteCount":0,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"Try printing out the following variable using phpinfo(): SERVER[\"HTTP_ACCEPT_ENCODING\"].\nMy suspect is that you don't have zip allowed- could be something different like \"gzip\" for example.
\n","author":{"@type":"Person","name":"Francesco Marchioni"},"upvoteCount":1}}}Reputation: 2485
I need to create a PHP page which starts automatically the download a file (I don't want to expose the Download link). I've tried with several examples on the web but all examples will end up with opening the file in the browser with the uncorrect content type. For example:
<?php
// We'll be outputting a ZIP
header("Content-type: application/zip");
// Use Content-Disposition to force a save dialog.
// The file will be called "downloaded.zip"
header("Content-Disposition: attachment; filename=downloaded.zip");
readfile('downloaded.zip');
?>
When I execute this page, the output on the browser is:
After trying all possible variants of this example my idea is that the problem is with my hosting environment. Which variable should I check and maybe ask to be enabled to my provider ?
Thanks!
Upvotes: 0
Views: 106
Reputation: 365
Here's the code I used back in the day:
header ("Content-Type: application");
header ("Content-Disposition: attachment; filename=\"$file\"");
header ("Content-Length: " . filesize ('./FILES/' . $file));
header ("Cache-Control: no-cache");
header ("Pragma: no-cache");
readfile ('./FILES/' . $file);
Just modify the content-type header ofc.
Upvotes: 0
Reputation: 4338
Try printing out the following variable using phpinfo(): SERVER["HTTP_ACCEPT_ENCODING"]. My suspect is that you don't have zip allowed- could be something different like "gzip" for example.
Upvotes: 1