Java 我可以使用内容类型:应用程序/强制下载进行文件下载吗?
这是我的代码,运行良好,这是正确的方法吗Java 我可以使用内容类型:应用程序/强制下载进行文件下载吗?,java,javascript,php,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");
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");
您需要像下面这样使用:
<?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;
}
?>
源URL:
谢谢和问候
Vivek