下载文件时获取二进制数据而不是实际文件时出错

时间:2013-08-29 22:09:01

标签: php

下载文件时出错,将二进制数据输入浏览器而不是实际文件,特别是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“ س©#ôںآ©سؤ™:Pا¾ýهس一个کؤVC«صژKOEچ“ژr \ IW“TUؤ'œ¥&LT;غAU&LT;§« ,«Æ¶-FF¥¥رک³ظ(WVÊG {i®&gt; streamxœه]ëڈإqXXVËs1Ë,¹;†¹ûAâDٹ7 [Hùùd'N“ضر'ے_JUWô¹sg| w±#ygخمVWuWWW?~Oâ(صAàüÉف¯çüك»éد‡ےxW ë®4£;了Hkزے_ؤƒSر〜U÷»ے的QpءC0; {=ƒ= U‰例如” q™IH,升{[:گJ>时ûي¢;ص,أو米)¤&GT;6فے°? R:^ UEI [ثٹ3​​¢¾米...ƒضŒ‡إVe的زز˚F{{0BMڑں°IUخVيئ[هYPüG6EàغN {[£'Rآدù•د¥·ءىفس¾¸÷<〜÷= /

这是我的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.';
    }
    ?>

0 个答案:

没有答案