PHP:如何在文件上传中删除不必要的文件名点? [英] PHP: How to remove unnecessary dots in filename on file upload?

查看:164
本文介绍了PHP:如何在文件上传中删除不必要的文件名点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来上传PHP文件。
我已经做了一些清理工作来删除难看的字符。



我也想删除文件名中的点,除了最后一个,表示文件扩展名。

任何人都有一个想法,我可以做到这一点。



例如,得到

  $ filename =water.fall_blue.sky.jpg; 
$ filename2 =water.fall_blue.sky.jpeg;

在这两种情况下都会返回这个结果..?

  water.fall_blue.sky 


解决方案

使用 pathinfo() 提取文件名(自PHP 5.2起,filename数组元素可用); str_replace()所有的点出来;并重新粘贴文件扩展名。

I have a script to upload files with PHP. I already do some cleaning to remove ugly characters.

I would also like to to remove dots in the filename, EXCEPT for the last one, which indicates the file extension.

Anyone has an idea how I could do that.?

For example, how would you get

$filename = "water.fall_blue.sky.jpg";
$filename2 = "water.fall_blue.sky.jpeg";

to return this in both cases..?

water.fall_blue.sky

解决方案

Use pathinfo() to extract the file name (the "filename" array element is available since PHP 5.2); str_replace() all the dots out of it; and re-glue the file extension.

这篇关于PHP:如何在文件上传中删除不必要的文件名点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆