我正在上传文件:
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
这样的文件名,以便只能访问文件名。
答案 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());