douyimin1083 2015-10-19 11:01
浏览 1584
已采纳

从Laravel中的存储中下载文件

I can't download files from storage. Firebug console shows

FileNotFoundException in File.php line 41: The file "C:\xampp\htdocs\ct\storage/30e9734e1f06bf751da5b3289994fb3f/34.pdf" does not exist

But files are existing in C:\xampp\htdocs\ct\storage\userdata\30e9734e1f06bf751da5b3289994fb3f folder. I think the file path I mentioned in code is not correct. Please help me to solve this issue.

filesystems.php

'root'   => storage_path('userdata'),

DownloadController.php

    public function show(TagambitionRequest $request)
        {
            $details             = User::select('id', 'created_at')->findOrFail(Auth::user()->id);
            $encrypt             = md5($details->id.$details->created_at);
            $directories         = Storage::files($encrypt);                                             // Listout Files
            foreach($directories as $values)
            {
                $split_folder_file = explode('/', $values);           //60e4dda43c442fe610bdbd4a0e5c3a12/19.pdf
                $splitted_file     = end($split_folder_file);         //19.pdf
                $explode_filename  = explode('.', $splitted_file);    //explode(19.pdf)
                $explode_name      = $explode_filename[0];            //19
                $file_extension    = $explode_filename[1];            //pdf
                if ($file_extension == 'pdf') {
                    $path  = storage_path().'/'.$encrypt.'/'.$splitted_file;
                    return response()->download($path, $splitted_file, ['Content-Type' => 'application/pdf']);
                }
            }
}
  • 写回答

1条回答 默认 最新

  • dtt27783 2015-10-19 19:30
    关注

    You've missed the userdata folder in your path so you need to change

    $path = storage_path().'/'.$encrypt.'/'.$splitted_file;

    to

    $path = storage_path().'/userdata/'.$encrypt.'/'.$splitted_file;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 收益高的广告联盟有哪些
  • ¥15 Android Studio webview 的使用问题, 播放器横屏全屏
  • ¥15 删掉jdk后重新下载,Java web所需要的eclipse无法使用
  • ¥15 uniapp正式环境中通过webapi将本地数据推送到设备出现的跨域问题
  • ¥15 xui建立节点,显示错误
  • ¥15 关于#单片机#的问题:开始、复位、十进制的功能可以实现,但是切换八进制的功能无法实现(按下按键也没有效果),把初始状态调成八进制,也是八进制可以实现但是切换到十进制不行(相关搜索:汇编语言|计数器)
  • ¥15 VINS-Mono或Fusion中feature_manager中estimated_depth是特征的深度还是逆深度?
  • ¥15 谷歌浏览器如何备份抖音网页数据
  • ¥15 分别有什么商家下面需要非常多的骑手为它工作?
  • ¥15 开机logo到Qt应用起来会黑屏将近两秒时间