【发布时间】:2020-01-31 21:38:44
【问题描述】:
我正在尝试通过 php 提供 docx 文件。它可以工作,但是在打开时我收到一条错误消息,说文件中有不可读的内容,我相信吗?
$attachment_location = $_SERVER['DOCUMENT_ROOT']."FILEPATH";
if (file_exists($attachment_location)) {
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Cache-Control: public"); // needed for internet explorer
header('Content-type: application/vnd.openxmlformats- officedocument.wordprocessingml.document');
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($attachment_location));
header("Content-Disposition: attachment; filename=FILENAME.docx");
readfile($attachment_location);
die();
} else {
die("Error: File not found.");
}
我尝试了一些建议,但找不到解决方案?谁能看出明显的遗漏?
【问题讨论】: