commit b52e7144cf8337475ee99f7ef6c17ebb0370183f
Author: Brückner Tamás <tamas.bruckner@integralvision.hu>
Date:   Tue Mar 15 16:56:30 2016 +0100

    Handle existing files in a better way.

diff --git a/upload_qc.module b/upload_qc.module
index 334842d..d10fb59 100644
--- a/upload_qc.module
+++ b/upload_qc.module
@@ -83,7 +83,7 @@ function upload_qc_form($form, &$form_state) {
 
 /**
 * Implements hook_file_validate().
-* This implementation includes two test: filesize and existance of db entry 
+* This implementation includes two test: filesize and existance of db entry
 * with the same URI.
 * If it returns errors, the upload process is blocked and the errors are displayed.
 * */
@@ -105,10 +105,8 @@ function upload_qc_file_validate($file) {
 // check if file URI already exists in db.
 // That prevents the AJAX error with duplicate entries for 'uri' in file_managed
   if (!empty($error_check)) {
-    $query_result = db_query('SELECT n.fid
-    FROM {file_managed} n WHERE n.uri = :uri', array(':uri' => $file->destination));
-    $record = $query_result->fetchObject();
-    if (is_object($record)) {
+    $file->destination = file_destination($file->destination, FILE_EXISTS_RENAME);
+    if ($file->destination == FALSE) {
       $errors[] = t("The file's name currently in use. Please wait a few seconds and try again.");
     }
   }
