16

I have the following code

$image_path = $_FILES["p_image"]["name"].time();

it names the file image02.jpg1335279888

but i want it to be named image02_1335279888.jpg

How can I achieve that?

4

3 回答 3

37
$path_parts = pathinfo($_FILES["p_image"]["name"]);
$image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension']
于 2012-04-24T15:10:12.393 回答
1

你可以检查这个:

$file = $_FILES["p_image"]["name"];
$array = explode('.', $file);
$fileName=$array[0];
$fileExt=$array[1];
$newfile=$fileName."_".time().".".$fileExt;
于 2015-02-20T07:37:02.187 回答
0
$image_path = $_FILES["p_image"]["name"];
$extension = pathinfo($image_path)['extension'];
$file = "image02_".time().".".$extension."";
echo $file;

输出:

image02_1641041826.jpg

于 2022-01-01T13:23:54.733 回答