Put date and time when the image exists in the folder with PHP

0

How can I put the date and time at the end of each image name if the same image name already exists in the folder?

I'm doing this, but it did not work out

if (isset($_FILES['files']) && !empty($_FILES['files'])) {

        $string = date('Y-m-d H:i:s');
 $string = str_replace(" ","",$string);
 $string = str_replace(":","_",$string);
 echo $string;


    $no_files = count($_FILES["files"]['name']);
    for ($i = 0; $i < $no_files; $i++) {
        if ($_FILES["files"]["error"][$i] > 0) {
            echo "Error: " . $_FILES["files"]["error"][$i] . "<br>";
        } else {
            if (file_exists('uploads/' . $_FILES["files"]["name"][$i])) {
                echo 'File already exists : uploads/' . $_FILES["files"]["name"].$string.[$i];

                 move_uploaded_file($_FILES["files"]["tmp_name"][$i], 'uploads/' . $_FILES["files"]["name"][$i]);
                echo 'File successfully uploaded : uploads/' . $_FILES["files"]["name"].$string.[$i] . ' ';

            } else {
                move_uploaded_file($_FILES["files"]["tmp_name"][$i], 'uploads/' . $_FILES["files"]["name"][$i]);
                echo 'File successfully uploaded : uploads/' . $_FILES["files"]["name"][$i] . ' ';
            }
        }
    }
} else {
    echo 'Please choose at least one file';
}
    
asked by anonymous 25.05.2018 / 21:40

0 answers