Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 upload original file name and extention

Tags:

sql

php

laravel-5

how can i upload original filename (file.jpg) to database when submitting file via form. Controller:

public function addCv(Request $request){
        $cv = Cv::create($request->all());
        $file = $request->file_name;
        $filename = $file->getClientOriginalName();
        Storage::putFileAs('public/uploads', $file, $filename);
        return redirect()->back();
    }

at the moment, this function uploads a path like this C:\xampp\tmp\php18DD.tmp. Instead of that i want just filename and extension (file.extension).

Storage is working fine - storing with original name.

like image 877
Benua Avatar asked Dec 19 '22 06:12

Benua


1 Answers

You could try

$file = $request->image->getClientOriginalName(); //Get Image Name

$extension = $request->image->getClientOriginalExtension();  //Get Image Extension

$fileName = $file.'.'.$extension;  //Concatenate both to get FileName (eg: file.jpg)
like image 157
Sreejith BS Avatar answered Jan 12 '23 10:01

Sreejith BS