Q:

file uploading to folder with current time

I've created successful a file uploading-system.
but how do I move the uploaded-file to a folder with a random name? (current time)
index.php:
<!doctype html>
<body>
   <form action="file-up.php" method="post" enctype="multipart/form-data">
        <table>
            <tr><td>File:</td><td><input type="file" name="myfile"></td></tr>
            <tr><td>&nbsp;</td><td><input type="submit" value="Upload"></td></tr>
        </table>
    </div>
    </form>
</body>
</html>

file-up.php:
<?php

$time = new DateTime();
$time->format('YmdHis'); 

$upload_dir = "uploads/";// . $time;
if (isset($_FILES["myfile"])) {
    if ($_FILES["myfile"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        move_uploaded_file($_FILES["myfile"]["tmp_name"], $upload_dir . $_FILES["myfile"]["name"]);
        echo "Uploaded File: " . $_FILES["myfile"]["name"];
    }
}
?>

A:

Try this  Working Code 
    <?php

$time = new DateTime();
$time->format('YmdHis'); 

//$upload_dir = "uploads/";// . $time;
$folder_name=date('mds');
$new_folder=mkdir($folder_name, 0777, true);
if(file_exists($new_folder)){

  echo "Folder already exist";
}
$upload_dir = $folder_name.'/';
if (isset($_FILES["myfile"])) {
    if ($_FILES["myfile"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        if(move_uploaded_file($_FILES["myfile"]["tmp_name"], $upload_dir. $_FILES["myfile"]["name"])){
        echo "Uploaded File: " . $_FILES["myfile"]["name"];
      } else {
        echo $new_folder .'/'. $_FILES["myfile"]["name"];
        echo "Folder created file not uploaded";
      }

    }
}
?>

