文件通过 MySQL Blob 类型储存,如何使用 Laravel 返回文件流?

我把文件存到数据库中,怎么返回文件流呢?
response()->download()
参数要的是文件路径,我应该怎么解决这个问题?
我一开始打算修改download方法,但是发现phpStorm跟踪不到实际的方法体又是为什么?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
Sparkfly
最佳答案
$filename = 'filename.txt';
$headers = [
    'Content-Encoding' => 'UTF-8',
    'Content-Type' => 'text/html;charset=UTF-8',
    'Content-Disposition' => "attachment; filename=\"$filename\"",
];

response()->stream(function () {
    $handle = fopen('php://output', 'w');
    fwrite($handle, 'something contents');

    // Close the output stream
    fclose($handle);
}, 200, $headers)->send();
5年前 评论
hana (楼主) 5年前
hana (楼主) 5年前
Sparkfly (作者) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
Sparkfly (作者) 5年前
讨论数量: 1
Sparkfly
$filename = 'filename.txt';
$headers = [
    'Content-Encoding' => 'UTF-8',
    'Content-Type' => 'text/html;charset=UTF-8',
    'Content-Disposition' => "attachment; filename=\"$filename\"",
];

response()->stream(function () {
    $handle = fopen('php://output', 'w');
    fwrite($handle, 'something contents');

    // Close the output stream
    fclose($handle);
}, 200, $headers)->send();
5年前 评论
hana (楼主) 5年前
hana (楼主) 5年前
Sparkfly (作者) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
hana (楼主) 5年前
Sparkfly (作者) 5年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!