I want save uploaded file with original name.What i must add to this code?
Below's my code
public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}
You may use the storeAs
method, which receives the path, the file name, and the (optional) disk as its arguments:
public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}
Upload files with original fileName.
if ($request->hasFile('image')) {
$file_path = $request->file('image')->storeAs('dir_name', request()->file('image')->getClientOriginalName(), 'optional_disk_name');
}
// pass the disk name as the third argument to the storeAs method: ex. local,s3,etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With