我試圖查看存儲在數據庫中的瀏覽器上的文件(即:excel表/ pdf /圖像)。在瀏覽器中使用php查看存儲在數據庫中的文件
我已經寫了一個從數據庫中下載文件的代碼,它正在工作,但我想在瀏覽器中顯示它。
下面是代碼:
<?php require_once('Connections/databasestudents.php'); ?>
<?php
$id = $_GET['id']; // ID of entry you wish to view. To use this enter "view.php?id=x" where x is the entry you wish to view.
$query = "SELECT fileContent, filetype FROM file where id = $id"; //Find the file, pull the filecontents and the filetype
$result = MYSQL_QUERY($query); // run the query
if($row=mysql_fetch_row($result)) // pull the first row of the result into an array(there will only be one)
{
$data = $row[0]; // First bit is the data
$type = $row[1]; // second is the filename
Header("Content-type: $type"); // Send the header of the approptiate file type, if it's' a image you want it to show as one :)
print $data; // Send the data.
}
else // the id was invalid
{
echo "invalid id";
}
?>
什麼情況是,view.php下載並沒有什麼看。
有什麼建議嗎?
PHP是在您的網絡服務器上配置不正確,或者未安裝。 – Sammitch
我所有的其他php頁面都可以工作!並且我下載了wamp服務器,它自動安裝了php,sql和apache – HaneenSu