Q:

Uploading file by User Id in mysql? 

I have two tables one is for users and one is for images 
All what I would like to achieve is that if I  log in I can be able to upload images for a user 
Since no user will be allowed  to upload images I wanna upload images for them and each and every user will be able to view his own images .  I have a working code to upload  multiple images but now
How to assign them to a specific user . 
the code bellow just uploads multiple images . 
<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="files[]" multiple/>
    <input type="submit"/>
</form>
<? php
$username = (isset ($_POST['username']));
if(isset($_FILES['files'])){
    $query = "INSERT into tish_images(`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`)
             VALUES(:FILE_NAME,:FILE_SIZE,:FILE_TYPE)";
    $stmt  = $con->prepare($query);
    $errors= array();
    foreach($_FILES['files']['tmp_name'] as $key => $error ){
        if ($error ! = UPLOAD_ERR_OK) {
            $errors[] = $_FILES['files']['name'][$key] . '  was not uploaded.'; 
            continue;
        }
        $file_name = $key.$_FILES['files']['name'][$key];
        $file_size = $_FILES['files']['size'][$key];
        $file_tmp  = $_FILES['files']['tmp_name'][$key];
        $file_type = $_FILES['files']['type'][$key];  
        if($file_size > 2097152){
            $errors[] = 'File size must be less than 2 MB';
            continue;
        }
        try{       
            $stmt->bindParam( ':FILE_NAME', $file_name , PDO::PARAM_STR );
            $stmt->bindParam( ':FILE_SIZE', $file_size, PDO::PARAM_STR );
            $stmt->bindParam( ':FILE_TYPE', $file_type, PDO::PARAM_STR );
            $stmt->execute();

            $desired_dir="image_uploads";

            if(is_dir($desired_dir)==false){
                mkdir($desired_dir, 0700);// Create directory if it does not exist
            }
            if(is_file($desired_dir. '/'.$file_name)==false){
                move_uploaded_file($file_tmp,$desired_dir. '/'.$file_name);
            }else{    //rename the file if another one exist
                $new_file=$desired_dir. '/'.$file_name.time();
                move_uploaded_file($file_tmp,$new_file) ;               
            }
        }catch(PDOException $e){
            $errors[] = $file_name . ' not saved in db.'; 
            echo $e->getMessage();
        }   
    }
    if(empty($error)){
        echo "Success";
    }
}
? >

A:

You  can do one thing .  Create a column for the user_id in the images table and when you insert the images insert the respective user_id accordingly.  So in the front end either you can have a drop-down of all the users or if you are using session to store user id then you can get that easily. 
Do let me know if you need any thing else.