<?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中的一段代碼。我指的是使用文件:當只需要pdf時,包含.php文件的PHP文件下載
<a href="file.php?name=First File">File 1</a>
這樣做的目的是,在鏈接的點擊,./curr/First File.pdf
應該下載。我確實得到了一個下載,但在檢查時,它是嵌入在文件中的pdf的網頁。任何人都可以協助
上面的代碼包含'file.php'文件中的所有內容? – Sirko 2013-03-08 14:00:29
否。圍繞下載有一個菜單系統等。以及登錄驗證。我應該失去所有,但PHP代碼? – Glenn 2013-03-08 14:03:40
@Splatter如果你在頁面上有其他的HTML,那將會在downlaod中得到輸出。你的'file.php'根本不應該有_ANY_標記。 – 2013-03-08 14:04:08