开发者

php force download extension

I'm trying to force a download so this is my code:

$file = 'test.m4r';
$mim开发者_JAVA技巧e = 'audio/aac';
header("Pragma: public"); // required
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header('Content-Description: File Transfer');
header("Content-Type: $mime");
header('Content-Length: ' . filesize($file));          
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);

The file extension should be .m4r, even though the mime is aac. On some computers it's downloaded as test.m4r, while on other computers, the file has extension of test.m4r.acc. How do I fix this problem?

Thank you!


You can lie about the mimetype, but besides that there isn't anything you can do. Try:

"application/octet-stream"

This might work, and is the default for unknown filetypes etc.


try this one

<?php header("Content-Type: application/force-download"); ?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜