I have used Input::file(\'upfile\')->getClientOriginalName()
to retrieve name of uploaded file but gives name with extension like qwe.jpg
.How do I g
In Laravel 7 the Fluent Strings were introduced which allows to do this in an extremely elegant way.
The basename
method will return the trailing name component of the given string:
use Illuminate\Support\Str;
$string = Str::of('/foo/bar/baz.jpg')->basename();
// 'baz.jpg'
If needed, you may provide an "extension" that will be removed from the trailing component:
use Illuminate\Support\Str;
$string = Str::of('/foo/bar/baz.jpg')->basename('.jpg');
// 'baz'
here you need to call php PATHINFO_FILENAME
$file = $request->file('fileupload')->getClientOriginalName();
$fileName = pathinfo($file,PATHINFO_FILENAME);
dd($fileName);
I use this code and work in my Laravel 5.2.*
$file=$request->file('imagefile');
$imgrealpath= $file->getRealPath();
$nameonly=preg_replace('/\..+$/', '', $file->getClientOriginalName());
$fullname=$nameonly.'.'.$file->getClientOriginalExtension();
You could try this
$file = Input::file('upfile')->getClientOriginalName();
$filename = pathinfo($file, PATHINFO_FILENAME);
$extension = pathinfo($file, PATHINFO_EXTENSION);
echo $filename . ' ' . $extension; // 'qwe jpg'
Try this:
$fullName = Input::file('image')->getClientOrginalName();
$extension = Input::file('image')->getClientOrginalExtension();
$onlyName = explode('.'.$extension,$fullName);
Or This:
$fullName = Input::file('image')->getClientOrginalName();
$extension = Input::file('image')->getClientOrginalExtension();
$fullNameLenght = strlen($fullName);
$extensionLenght = strlen($extension);
$nameLength = $fullNameLenght - ($extensionLength + 1);
$onlyName = strpos($fullName, 0, $nameLength);
you can use this
Input::file('upfile')->getClientOriginalExtension()