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
This one is pretty clean:
$fileName = pathinfo($fullFileName)['filename'];
Equivalent to:
$fileName = pathinfo($fullFileName, PATHINFO_FILENAME);
https://php.net/manual/en/function.pathinfo.php
Get the file name using getClientOriginalName(); then use the explode function to get the name and the image format as shown below:
$image=Input::file('image');
$fullName=$image->getClientOriginalName();
$name=explode('.',$fullName)[0];
On Laravel 5.4 or Lumen 5.4, this may be a useful resource here.
preg_replace('/\..+$/', '', 'qwe.jpg')
or
explode('.', 'qwe.jpg')[0]
You can use this code too.
if ($request->hasfile('filename')) {
$image = $request->filename;
$namewithextension = $image->getClientOriginalName(); //Name with extension 'filename.jpg'
$name = explode('.', $namewithextension)[0]; // Filename 'filename'
$extension = $image->getClientOriginalExtension(); //Extension 'jpg'
$uploadname = time() . '.' . $extension;
$image->move(public_path() . '/uploads/', $uploadname);
}
Laravel uses Symfony UploadedFile
component that will be returned by Input::file()
method.
It hasn't got any method to retrive file name, so you can use php native function pathinfo()
:
pathinfo(Input::file('upfile')->getClientOriginalName(), PATHINFO_FILENAME);