duanlu1876 2019-07-17 10:11
浏览 476

下载后文件为空

I'm trying to download files of different types in a database's blob column. When I open files and images, all the files are empty. What's going wrong?

$file = DB::table('files')->where('id', $fileId)->get()[0];

header("Content-length: $file->file_size");
header("Content-type: $file->file_type");
header("Content-Disposition: attachment; filename=$file->file_name");
ob_clean();
flush();
echo $file->file;
  • 写回答

1条回答 默认 最新

  • dptdb84606 2019-07-17 10:53
    关注

    use the ready to use laravel response for file donwload

    $file = DB::table('files')->where('id', $fileId)->get()[0];
    return response()->streamDownload(function () use ($file) {
        echo $file->file;
    }, $file->file_name);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序