0
私はソースが表示されていないファイルのダウンロードを可能にするために次のコードを書いています。PHPファイルダウンヘッダ()
この例では、ファイル 'test.pdf'はダウンロードされていますが、破損しています。
これはどのような理由が考えられますか?
$path = 'http://www.domain.org/images/uploads/test.pdf';
// Directory Path
$directory_path_filename = str_replace('http://www.domain.org/', '', $path);
$filepath = '/var/sites/l/domain.org/public_html/'.$directory_path_filename;
if (file_exists($filepath)) {
$finfo = finfo_open(FILEINFO_MIME);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename= ' . basename($filepath));
header('Content-Length: ' . filesize($filepath));
header('Expires: 0');
finfo_close($finfo);
ob_clean();
flush();
readfile($filepath);
exit;
}
こんにちは。ありがとうございますが、これでも同じ問題が発生します。ダウンロードしたファイルは一度開くことはできません。 – ccdavies
そのような場合はおそらく、ヘッダーの前にいくつかの出力があります... noiteや何かのように、完全なコードを投稿してください。 –