从Laravel

时间:2015-10-19 11:01:07

标签: php laravel laravel-5

我无法从存储中下载文件。 Firebug控制台显示

  

File.php第41行中的FileNotFoundException:文件   " C:\ XAMPP \ htdocs中\克拉\存储/ 30e9734e1f06bf751da5b3289994fb3f / 34.pdf"   不存在

但文件存在于C:\xampp\htdocs\ct\storage\userdata\30e9734e1f06bf751da5b3289994fb3f文件夹中。我认为我在代码中提到的文件路径不正确。请帮我解决这个问题。

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 个答案:

答案 0 :(得分:0)

您错过了路径中的userdata文件夹,因此您需要更改

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

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