我可以使用Content-type:application / force-download进行文件下载吗?

时间:2015-05-11 09:53:05

标签: java javascript php

这是我的代码,它工作正常,这是正确的方法吗?

header("Content-Description: File Transfer");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=name.extn");
header("Content-length: $fsize");
header("Cache-control: private");

1 个答案:

答案 0 :(得分:-1)

您需要使用以下内容:

<?php
$file = 'filename.doc'; //your file name with proper path here.

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>

来源网址:http://php.net/manual/en/function.readfile.php

谢谢&amp;的问候,

<强>的Vivek