我需要你對這個問題的建議.. 我的意圖是,我有一個單詞文件上傳到分貝作爲BLOB內容...我有它顯示爲我的網頁中的鏈接..文件下載不起作用php
當我點擊鏈接時,Word文檔應該被下載... 我收到下面的錯誤消息,點擊鏈接後.. 警告:無法修改頭信息 - 頭已發送(輸出開始/家用/ stthohuu /的public_html/SP/archive_newsletter.php:8)
看到下面的代碼...
</head>
<body>
<?php
//database connection
$con = mysql_connect('localhost', 'abc', 'abc') or die(mysql_error());
//select database
$db = mysql_select_db('stthohuu_church', $con);
$query = "SELECT id, name FROM newsletter order by id desc";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "No files found in DB<br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="archive_newsletter.php?id=<?php echo urlencode($id);?>"
><?php echo urlencode($name);?></a> <br>
<?php
}
}
mysql_close();
?>
</body>
</html>
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
$con = mysql_connect('localhost', 'abc', 'abc') or die(mysql_error());
$db = mysql_select_db('stthohuu_church', $con);
$id = $_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM newsletter WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
ob_clean();
flush();
echo $content;
mysql_close();
exit;
}
?>
這也適用於XAMPP但不是在Web服務器:(
爲什麼你不喜歡這樣:上傳你的文件到一個目錄,並將文件地址添加到您的數據庫,而不是整個文件! 我不認爲你能夠以這種方式下載文件。 –
謝謝,但在這種情況下,我將能夠從另一個目錄下載文件...如果是這樣,如何...任何指導鏈接? –
我知道您可以從服務器上的任何目錄下載文件。 請參閱下面的鏈接,我認爲它很有用:http://www.php.net/manual/en/function.readfile.php –