How can I add a time stamp to a file name uploaded with $_File before the file extension

后端 未结 2 1834
闹比i
闹比i 2021-02-07 09:41

I have the following code

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

it names the file image02.jpg1335279888

bu

相关标签:
2条回答
  • 2021-02-07 10:12
    $path_parts = pathinfo($_FILES["p_image"]["name"]);
    $image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension']
    
    0 讨论(0)
  • 2021-02-07 10:30

    You can check this one:

    $file = $_FILES["p_image"]["name"];
    $array = explode('.', $file);
    $fileName=$array[0];
    $fileExt=$array[1];
    $newfile=$fileName."_".time().".".$fileExt;
    
    0 讨论(0)
提交回复
热议问题