0
<?php

$file = $_GET['name'];

$path = './curr/'.$file.'.pdf'; // the file made available for download via this PHP file
$mm_type="application/pdf"; // modify accordingly to the file type of $path, but in most cases no need to do so

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");

readfile($path); // outputs the content of the file

?>

これは、file.php 内のコードのスニペットです。以下を使用してファイルを参照しています。

<a href="file.php?name=First File">File 1</a>

その意図は、リンクをクリックすると./curr/First File.pdfダウンロードすることです。私はダウンロードを取得しますが、検査すると、ファイルに埋め込まれたpdfを含むWebページです。誰でも助けてもらえますか?

4

2 に答える 2

0

コンテンツタイプを次のように変更してみてください:

header("Content-Type: application/force-download");
于 2013-03-08T14:00:37.220 に答える