下载文件时出错,将二进制数据输入浏览器而不是实际文件,特别是pdf文件。 我在mysql文件中使用BLOB数据类型。
v?-x¢b(°ه-z zڈ÷÷μï½TTکêùQïىxùS - jîآ·×Yï¹oف5 KK÷¾oصتمح+¾|œ:و†lo n“w w w w w w w w w w w w†Æ +أجشƒœرد;-ںê•ؤ...¬RH|ħ镝ے#½= @'X'§¾ذXœtz”†رص0 ALو>“ء²{÷ڈے½} F;âB|کژ¯“كگ咋طPeüpy,¥¼تŒ•MR±瓦特گçي¢âٹ “¬} Fz的ى3¢e¾NAو^ 4è¬{J =¤ر³جسâل&LT;¶-5Mz&安培; @ + MYN1¨çںq)زêذش£中号NJ] T,‡A *×h0ï3D¤6غإQ.μg¬€ء¥瓦特«ي|م+的“çكUMاEOEغ½وؤ〜لà...½ں$ /‡ھ(·@‡]μظ吨حîز4»CQEں[°ظ5گ+ E'ہU4> MQD™@ں|?‡فژd×E×F * Xز”!¹'پ÷我?·U×سخ½中号أ}ق奥斯特$ A'ظ克ء升”ƒ= FRن(RإهPY2ش2ج:طQî49œtرA3kfفذ'){¯'7ذE =»نx¾ةLb的|'شا×Sل‡ةأجô‰ - ثSùy|y†üھc取代; ا/'>Zç9V·بش&安培;¸ةq“S y时عLZگïگ_v¼ئدH =ل'ےĴت...£ںبb÷U;?!·Lآڑ>电子ڑƒ}ك˚Fپں>ûنVI&gt;“中]¤vçW†•乙ڑ'! ج=¥4†é1حزہحٹ,é?“ل¢qعض4 < فل吨ڑ克ؤbوT§ةOEEچ8“ س©#ôںآ
这是我的PHP代码下载
<?php
$company =$_GET['company'];
// Make sure an ID was passed
if(isset($_GET['id'])) {
// Get the ID
$id = intval($_GET['id']);
// Make sure the ID is in fact a valid ID
if($id <= 0) {
die('The ID is invalid!');
}
else {
// Connect to the database
$dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Fetch the file information
$query = "
SELECT mime, name, size, data
FROM $company
WHERE id = $id";
$result = $dbLink->query($query);
if($result) {
// Make sure the result is valid
if($result->num_rows == 1) {
// Get the row
$row = mysqli_fetch_assoc($result);
// Print headers
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
// Print data
echo $row['data'];
}
else {
echo 'Error! No image exists with that ID.';
}
// Free the mysqli resources
@mysqli_free_result($result);
}
else {
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
@mysqli_close($dbLink);
}
}
else {
echo 'Error! No ID was passed.';
}
?>