Here is my the syntax to get the Uploaded Filename with extension and Getting only the Extension
$name = Input::file('photo')->getClientOriginalName();
$extension = Input::file('photo')->getClientOriginalExtension();
Here if i upload a file named file.jpg
.Then i will get
$name = file.jpg
$extension = jpg
Is there any predefined way to get only the file name i.e., file
without using any string replace.
If not kindly suggest a way to achieve in it str replace or any other way.
As an alternative, if you do not want string operations you can use pathinfo()
:
$name = 'file.jpg';
$file_name = pathinfo($name, PATHINFO_FILENAME); // file
$extension = pathinfo($name, PATHINFO_EXTENSION); // jpg
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