我正在通过 php 脚本下载文件,除了一个丑陋的事实外,一切都运行良好。下载的文件保留相同的 url 并附加原始名称。下载文件时如何保持相同的文件名?
http://bachday.com/index.php?page=custom&file=mmailer/download.php?mfile=sample.docx
if (isset($_GET['mfile'])) {
$file = $_SERVER['DOCUMENT_ROOT'].'/oc-content/plugins/mmailer/pfile/'.$_GET['mfile'];
if (file_exists($file) && is_readable($file) && preg_match('/\.docx$/',$file)) {
header('Content-Type: application/docx');
header("内容配置:附件;文件名=\"$file\"");
读取文件($文件);
/*
header("过期时间:0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo (readfile($file));*/
}
别的
{
header("HTTP/1.0 404 Not Found");
echo "错误 404: 未找到文件:
$file ";
}