PHPスクリプトを介してファイルをダウンロードしていますが、1つの醜い真実を除いてすべてが完全に機能します。ダウンロードしたファイルは同じ 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: アプリケーション/docx');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($ファイル);
/*
header("有効期限: 0");
header("Cache-Control: no-cache, must-revalidate");
header("プラグマ: キャッシュなし");
echo (readfile($file));*/
}
そうしないと
{
header("HTTP/1.0 404 見つかりません");
echo "エラー 404: ファイルが見つかりません:
$file ";
}