我必須使用PHP從MySQL數據庫下載最新上傳的PDF文件。該文件可以查看,但保存到本地文件夾,而不是保存爲.pdf,它保存.php。並且.php文件包含編碼數據。使用PHP從數據庫下載PDF文件
任何人都可以建議我如何下載/保存.pdf文件?代碼是:
<?php
include 'connection.php';
$sql=mysqli_query($connection,"Select name,content from ekalp where id = (select max(id) from ekalp)");
$result=mysqli_fetch_assoc($sql);
//$resu=$result['name'];
$result=$result['content'];
echo $result."<br>";
$filename = $result.'pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
ob_clean();
ob_flush();
@readfile($filename);
mysqli_close($connection);
?>
http://yogeshchaugule.com/blog/2013/how-display-pdf-browser-php – himansu 2014-12-03 06:00:59