alert only file names selected from file input

lukip006

New Member
I have this ajax call which checks if the selected file names of a multiple file input already exist in the database. and if they do, it alerts a message telling them. The problem is I can only get it to alert all the file names from the result loop. how can I edit it so that it only alerts the file names that were selected? Thanks. \[code\]var file = $('#file')[0];$.get('existing-filenames.php', function(data){ for (var i=0; i<file.files.length; i++) { var fname = file.files.name; if(~data.indexOf(fname)){ // only alert selected file names alert("these files already exist:" + data); return false; } }},'json');\[/code\]and in existing-filenames.php\[code\]$allfiles = $db->query("SELECT filename FROM files WHERE email = '$_SESSION'");$result = [];while( $files = $allfiles ->fetch_assoc() ){ $result[] = $files['filename']; } echo json_encode($result);\[/code\]and html\[code\]<input name = "file[]" type = "file" id = "file" multiple />\[/code\]
 
Back
Top