我想給PHP內聯網的用戶提供打開/保存PDF文件的可能性,這些文件位於Apache服務器的文件夾中。 PDF有公司的私人信息,所以我不想把它們放在網絡文件夾中。打開/保存位於服務器文件夾中的PDF
echo '<form name="openpdf" method="POST" action="downloadPDF.php">';
echo '<input type="hidden" name="pdf">';
echo'</form>';
<tr>
<td> PDFFile1 </td>
<td><a href=javascript:void(null); onclick='document.openpdf.pdf.value="c:\pdfs\example.pdf";document.openpdf.submit(); return false;'><IMG src="img/pdf.jpg"></a></td></tr>
downloadPDF.php:
<?
$pdf=$_POST["pdf"];
if (file_exists($pdf)) {
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($pdf));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($pdf));
ob_clean();
flush();
readfile($pdf);
exit;
}
?>
問題是,當打開用戶/保存文件,路徑指向該文件夾,但在客戶端PC,而不是在服務器上。
的一般過程是下載,編輯並把它放回去。但是你想究竟是什麼? – SuperSaiyan 2012-07-09 17:01:09
打開存儲在apache服務器上的文件夾中的pdf文件。 – 2012-07-09 17:16:03
據推測,一旦通過內聯網提供,「在客戶端PC」中的副本位於臨時文件夾中,由瀏覽器保存。這很正常 - 如果您想要保存到集中式副本,則可能需要使用網絡文件服務器。 – halfer 2012-07-09 19:27:16