drvpvmz16241016 2018-10-10 10:47
浏览 81

来自数据库longblob的readfile()

I am working on a legacy system that stores files in the DB as LONGBLOB

What I am trying to achieve is that the user can visit a URL and download a specific file. Now on the part where I try to read the file, I believe I am missing something. PHP is giving me readfile() expects parameter 1 to be a valid path, string given [] []

So I can deduce that I cannot directly feed the LONGBLOB into the readfile() method. Is there another way of piping the file out to the user?

Here is the code I am trying to use at the moment:

$stmt = $this->db->prepare('SELECT * FROM DOC_Documents WHERE DOC_ID = ?');
$stmt->execute([$docID]);
$document = $stmt->fetch();

$filename = str_replace(' ', '', $document['DOC_Name']);
$filename .= '.';
$filename .= $document['DOC_Extension'];

header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header('Content-Description: File Transfer');
header("Content-Type: " . $document["DOC_Type"]);
header("Content-Disposition: attachment; filename=" . $filename);
readfile(trim($document['DOC_File'])); 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题