Php 如何在laravel中下载上传的文件

Php 如何在laravel中下载上传的文件,php,laravel,file,Php,Laravel,File,我想创建一个函数来下载存储中上传的文件,但它总是显示一个错误代码:文件“D:\xampp php 7.2.2\htdocs\siapKerja\u laravel\public\files/22”不存在 public function show($idFile) { $file = public_path(). "/files/"; return Response()->download($file.$idFile);$ } Route::get('/verifi

我想创建一个函数来下载存储中上传的文件,但它总是显示一个错误代码:文件“D:\xampp php 7.2.2\htdocs\siapKerja\u laravel\public\files/22”不存在

public function show($idFile)
 { 
    $file = public_path(). "/files/";
    return Response()->download($file.$idFile);$
 } 

Route::get('/verifikasi/pkwt/download/{id}', 'FileController@show')->name('downloadFile');

您需要提供文件的完整url

尝试添加文件扩展名:

$extension=“.png”//或任何类型的文件

return Response()->下载($file.$idFile.$extension)

保存文件时,您还可以在存储文件时获得扩展名:

$extension = $request->file('file')->extension();

我希望它能帮助你。我上传的文件在“文件”文件夹,而不是在存储文件夹。您只需根据该设置进行更改。根据您的设置设置内容类型 上传的文件

我的控制器代码是

public function  openPdf(Request $request,$docFile)
{   

    $file='/var/www/html/laravelQuiz/public/files/'.$docFile;
     $extension = explode(".",$docFile);

     foreach($extension as $extensions){
        if($extensions == 'pdf'){
           $content_types =  'application/pdf';
        }elseif($extensions == 'doc'){
           $content_types =  'application/msword';
        }elseif($extensions == 'txt'){
            $content_types =   'application/octet-stream';
        }elseif($extensions == 'docx'){
            $content_types =     'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
        }elseif($extensions == 'ppt'){
            $content_types = 'application/vnd.ms-powerpoint';
        }elseif($extensions == 'odt'){
            $content_types = 'application/vnd.ms-powerpoint';
        }elseif($extensions == 'txt'){
            $content_types = 'text/plain';
        }
     }
     $content = file_get_contents($file);               
     return Response::make($content, 200, array('content-type'=>$content_types));

}

你有什么问题吗?提一下你的问题,不要提要求Shraddha
public\u path()
将给出路径直到
”/var/www/html/laravelquick/public/