I am uploading the file :
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;
}
The file moves to the project/public/uploads/user_files/cnic
successfully,
But the filename which goes also to the database have the remote server directory path like /var/www/html/baseApi/5927bcb59ba4fcar.png
How can i be able to store the filename like https://example.com/public/uploads/user_files/cnic/5927bcb59ba4fcar.png
so it can be use be only accessing the filename.
You could replace
$userDetails->cnicFrontUrl = $picName;
with
$userDetails->cnicFrontUrl = url("/public/uploads/user_files/cnic")."/".uniqid().
$request->file('cnicFrontUrl')
->getClientOriginalName();
or
$userDetails->cnicFrontUrl = asset($destinationPath. "/" . uniqid() .
$request->file('cnicFrontUrl')
->getClientOriginalName());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.