douyimin1083 2015-10-19 03: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 11: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;

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

报告相同问题?