php 如何在文件扩展名之前为使用 $_File 上传的文件名添加时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10300690/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:51:43 来源:igfitidea点击:
How can I add a time stamp to a file name uploaded with $_File before the file extension
提问by code511788465541441
I have the following code
我有以下代码
$image_path = $_FILES["p_image"]["name"].time();
it names the file image02.jpg1335279888
它命名文件 image02.jpg1335279888
but i want it to be named image02_1335279888.jpg
但我希望它被命名 image02_1335279888.jpg
How can I achieve that?
我怎样才能做到这一点?
回答by Sethunath
$path_parts = pathinfo($_FILES["p_image"]["name"]);
$image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension']
回答by Jumper Pot
You can check this one:
你可以检查这个:
$file = $_FILES["p_image"]["name"];
$array = explode('.', $file);
$fileName=$array[0];
$fileExt=$array[1];
$newfile=$fileName."_".time().".".$fileExt;

