Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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?

like image 370
code511788465541441 Avatar asked Apr 24 '12 15:04

code511788465541441


People also ask

How do you add a timestamp to a name in HTML?

Simply concat "_" + System. currentTimeMillis() to the filename ? If instead of the milliseconds you want the intellegible timestamp, simply use a DateFormat as shown in the other answer.

What is move_ uploaded_ file in PHP?

The move_uploaded_file() function moves an uploaded file to a new destination. Note: This function only works on files uploaded via PHP's HTTP POST upload mechanism. Note: If the destination file already exists, it will be overwritten.

How to get uploaded file path in PHP?

php $NameOriginal = $_FILES["UploadFileName"]['name']; $Typo_Image = $_FILES["UploadFileName"]['type']; $name_Temp = $_FILES["UploadFileName"]['tmp_name']; ?>


2 Answers

$path_parts = pathinfo($_FILES["p_image"]["name"]);
$image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension']
like image 69
Sethunath K M Avatar answered Oct 12 '22 15:10

Sethunath K M


You can check this one:

$file = $_FILES["p_image"]["name"];
$array = explode('.', $file);
$fileName=$array[0];
$fileExt=$array[1];
$newfile=$fileName."_".time().".".$fileExt;
like image 32
Jasper Avatar answered Oct 12 '22 14:10

Jasper