How to avoid duplicate file in upload using PHP?
<p>Good day everyone, I want to prevent uploading a file if the name and file extension match one of the saved records. My code below works but how can I avoid duplicate entries?</p>

<pre><code>"My sample array"
Array
(
    [upload-file] =&gt; Array
        (
            [name] =&gt; Penguins.jpg
            [type] =&gt; image/jpeg
            [tmp_name] =&gt; C:\xampp\tmp\phpC87.tmp
            [error] =&gt; 0
            [size] =&gt; 777835
        )

)

case 'upload-file':

    $arr = [ 
        ":userid" =&gt; $_SESSION['loggedIn_PH'][0]['user_id'],
        ":filename" =&gt; $_FILES['upload-file']['name'],
        ":filelink" =&gt; $_FILES['upload-file']['tmp_name']
        ];

        $allowed =  array('xls','xlsx');
        $filename = $_FILES['upload-file']['name'];
        $ext = pathinfo($filename, PATHINFO_EXTENSION);

        if(!in_array($ext,$allowed) ) {
            $response_code = -1;
        }else{
            $response_code = 1;
            $folder = time();
            mkdir("path/".$folder);
            $file = "path".DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR.$_FILES['upload-file']['name'];
                    move_uploaded_file($_FILES['upload-file']['tmp_name'], $file);

        $query = "INSERT INTO file_rec_tbl ( `file_name`, `file_datetime`,`file_link`, `user_id` )
                    VALUES (:filename, '".date('Y-m-d H:i:s')."',:filelink,:userid)";

        $stmt = $con -&gt; prepare( $query );
        $stmt -&gt; execute( $arr );

    }

    exit(json_encode(array('r_code' =&gt; $response_code)));
    break;
</code></pre>