0

while uploading i want to rename the image name to date and time.i have a code like this

date_default_timezone_set('UTC');
$today = date("Y-m-d");
$_SERVER['REQUEST_TIME'];
$dt = $today.'_'.time();
$uploadDir = '/upimg/logoimg/'.$dt.'';

$filename = $_FILES['logoimage']['name'];
    $tmpname = $_FILES['logoimage']['tmp_name'];

    $filePath = $uploadDir . $filename;
    $result1 = move_uploaded_file($tmpname, $filePath);

after uploading that image path is like date_time_imagename

    /upimg/logoimg/2014-04-09_139704740331BG-NHTB-AGUMBE1_1098618g.jpg

instead of that i want to display date and time only

2
Contributors
2
Replies
9
Views
3 Years
Discussion Span
Last Post by malatamil
0

one of the many ways of doing this is to get the image file extension first.

for example,

$this_ext = pathinfo($filename, PATHINFO_EXTENSION);

The above codes will give us the image extension of the uploaded image.

The next step is to rename the image

$result1 = move_uploaded_file($tmpname, $uploadDir.'.'.$this_ext);
0

image is not stored in server by using this
$this_ext = pathinfo($filename, PATHINFO_EXTENSION);
The above codes will give us the image extension of the uploaded image.

The next step is to rename the image

$result1 = move_uploaded_file($tmpname, $uploadDir.'.'.$this_ext);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.