>我试图实现应用程序来下载存储在我的服务器中的word,excel,powerpoint文件。我的源代码适用于 pdf。这是我的pdf文件下载源代码。对于这三种类型,需要做哪些更改。
$fullPath= 'http://192.168.12.12/test/public/video/08/01/0107_9762.pdf';
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=0108_9762.pdf");
$pdfiledata = file_get_contents($fullPath);
echo $pdfiledata;
exit;
我解决了我的问题。通过任意分析字节,它从空格开始需要清除该空间。这是任何人的工作代码。
$fullPath = $fullPath= 'http://192.168.12.12/test/public/doc/08/01/0107_9762.docx';
$fileName = "mydoc.docx";
$headers = get_headers($fullPath, 1);
$contentType = $headers['Content-Type'];
ob_start("");
header("Content-type:".$contentType);
header("Content-Disposition: attachment; filename=".$fileName);
ob_end_clean();
$pdfiledata = file_get_contents($fullPath);
ob_clean(); // discard any data in the output buffer (if possible)
flush(); // flush headers (if possible)
echo $pdfiledata;
exit;