【发布时间】:2016-03-15 06:54:30
【问题描述】:
请我是 php 新手,我无法弄清楚为什么这段代码不起作用。我尝试下载这个 docx 文件,但是它会下载文件,但是当我打开文件时,文件上没有显示任何内容。它是空的。我相信文件已损坏,这是由于代码造成的。代码如下:
<?php
if(isset($_POST['file_name']))
{
$file = $_POST['file_name'];
echo $file;
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment; filename='.$file.'');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile('resumeFolder/'.$file);
exit();
}
?>
<form action="force_download.php" method="post" name="downloadform">
<input name="file_name" value=" Aunt_CC_Letter.docx" type="hidden">
<input type="submit" value="Download the MP3">
</form>
【问题讨论】:
标签: php download header http-headers docx