このようなことはできますか?
ob_start();
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=".$title);
header("Content-Length: ".$size);
header("Content-Transfer-Encoding: binary");
readfile($path);
ob_end_flush();
現在、ダウンロードする正しい名前のファイルを取得していますが、ファイルの内容は、上記のコードを含む php からの html 出力です。
$path が正しいことを確認しました。悪い $size はこれを引き起こしますか? また、ob_start() の直後に ob_flush() を試みました。
編集: 以下の現在のコード:
if (file_exists($path)){
ob_start();
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=".$title);
header("Content-Length: ".filesize($path));
header("Content-Transfer-Encoding: binary");
readfile($path);
ob_end_flush();
die();
} else die ("Not Found");
上記のコードは同じ問題を引き起こします。ファイルがダウンロードされ、正しく名前が付けられ、明らかに存在し、正しいサイズですが、ファイルの内容はページの html 出力です。
前もって感謝します
これが(誤って)ダウンロードされるファイルの最後にあることに気付きました:「int(14)コンテンツ」
しかし、コードのどこにも意図的にこれを出力していません。