Laravel Lumen文件上传完整路径

时间:2017-05-26 05:53:59

标签: php laravel file-upload remote-access lumen

我正在上传文件:

if ($request->hasFile('cnicFrontUrl')) {
    $picName = $request->file('cnicFrontUrl')->getClientOriginalName();
    $picName = base_path() . uniqid() . $picName;
    $destinationPath = "uploads/user_files/cnic";
    $request->file('cnicFrontUrl')->move($destinationPath, $picName);
    $userDetails->cnicFrontUrl = $picName;
}

文件成功移动到project/public/uploads/user_files/cnic

但是同样到数据库的文件名也有远程服务器目录路径,如/var/www/html/baseApi/5927bcb59ba4fcar.png

我如何能够存储https://example.com/public/uploads/user_files/cnic/5927bcb59ba4fcar.png这样的文件名,以便只能访问文件名。

1 个答案:

答案 0 :(得分:0)

你可以替换

$userDetails->cnicFrontUrl = $picName;

$userDetails->cnicFrontUrl = url("/public/uploads/user_files/cnic")."/".uniqid(). 
                                  $request->file('cnicFrontUrl')
                                          ->getClientOriginalName();

$userDetails->cnicFrontUrl = asset($destinationPath. "/" . uniqid() . 
                                   $request->file('cnicFrontUrl')
                                           ->getClientOriginalName());