laravel 获取没有扩展名的文件名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27497304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting File Name without Extension
提问by AngularAngularAngular
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
在这里,如果我上传一个名为file.jpg
.The的文件,那么我会得到
$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.
有没有任何预定义的方法来只获取文件名,即file
不使用任何字符串替换。如果不请提出一种在其中实现 str 替换或任何其他方式的方法。
回答by Kevin
As an alternative, if you do not want string operations you can use pathinfo()
:
作为替代方案,如果您不想要字符串操作,您可以使用pathinfo()
:
$name = 'file.jpg';
$file_name = pathinfo($name, PATHINFO_FILENAME); // file
$extension = pathinfo($name, PATHINFO_EXTENSION); // jpg