删除文件上传时的文件扩展名
我现在正在为一个网站编写代码,该网站上传图像,然后以图库样式显示它们。我想要发生的是将图像的文件名作为图像的名称输入到站点的数据库中。但是,仅使用 $_FILES['images']['name'];
即可为我提供文件名,但在末尾附加文件扩展名。如何删除文件扩展名以便可以单独使用文件名?
I'm writing the code for a website right now that's uploads images and then displays them gallery style. What I would like to happen is for the file name of the image to be entered into the site's database as the name of the image. However, just using $_FILES['images']['name'];
gives me the file name but with the file extension attached at the end. How would I remove the file extension so I can use the file name by itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
pathinfo()
函数 (docs)。You can use the
pathinfo()
function (docs).只需使用 preg_replace 即可:
Just use preg_replace:
您可以使用
rename
删除扩展名:-> http://www.php.net/manual/en/function.rename.php
You can use
rename
to remove the extension:-> http://www.php.net/manual/en/function.rename.php
正如我上面的评论所暗示的那样,这取决于您在文件名中认为的名称和扩展名是什么。
直到最后一个点的所有内容:
直到第一个点的所有内容:
它们看起来相同,但第一个从字符串末尾查找第一个点,从字符串开头查找第二个点。
As my comment above implies, it depends on what you consider in the filename to be the name and what is the extension.
everything up to the last dot:
everything up to the first dot:
they look the same, but the first one looks for the first dot from the end of the string and the second one from the start of the string.