重命名多图像上传

here is my problem i need to rename the images when someone upload it, i want to use date and time and to created the $datatime value and i dont know how to make it works can some tell me how to do it? any help much be appreciated... Much Thanks

<?php if(isset($_POST['action'])=='uploadfiles') {
$time = time();
$date = date('Y-m-d');
$datetime = "$time" . "$date";

$upload_directory   ='uploads/';  
$count_data         =count($_FILES['data']) ;
$upload             = $_FILES['data']['name'][$x].',';  

for($x=0;$x<$count_data;$x++) {
    $upload .= $_FILES['data']['name']["$x" . ""].',';
    move_uploaded_file($_FILES['data']['tmp_name'][$x], $upload_directory . $_FILES['data']['name'][$x]); ##### upload into your directory     }

//echo "upload successfully..";
$con="INSERT INTO inmuebles (foto1) values ('$upload')";
$query=mysql_query($con); } ?>

Change here:

move_uploaded_file(
  $_FILES['data']['tmp_name'][$x],
  $upload_directory . $datetime . $_FILES['data']['name'][$x]
); ##### upload into your directory

Here the $datetime should be the string containing the timestamp.

Try the following:

$ext = pathinfo($_FILES['data']['name'][$x], PATHINFO_EXTENSION);
$newname = $datetime . '.' . $ext;
move_uploaded_file($_FILES['data']['tmp_name'][$x],
                   $upload_directory . $newname);

This will replace the current filename, and maintain the extension of the originally uploaded file.

If you want to maintain the original filename and simply append the datetime to it, use the following:

$info = pathinfo($_FILES['data']['name'][$x]);
$ext = $info['extension'];
$name = $info['filename'];
$newname = $name . $datetime . '.' . $ext;
move_uploaded_file($_FILES['data']['tmp_name'][$x],
                   $upload_directory . $newname);

Using date and time is a poor way to uniquely label anything because the limit of your fidelity is 1 item per second and computers are WAY faster than that, along with the fact more than 1 person could be using the upload at the same time. Instead use something build for this such as UUID (aka GUIDs). You can just use the uniqid() function in PHP which is very basic or if you read the comments somebody has written a UUID function (use version 5).

http://php.net/manual/en/function.uniqid.php