Author: sevein
Date: Tue Sep 15 18:45:09 2009
New Revision: 3332

Log:
Multi-upload form: repeated files detection by md5 checksum. Warning messages 
must be improved in next revisions.

Modified:
   trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
   trunk/web/js/multiFileUpload.js

Modified: trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php       
Tue Sep 15 17:04:27 2009        (r3331)
+++ trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php       
Tue Sep 15 18:45:09 2009        (r3332)
@@ -55,6 +55,8 @@
       // Move file to web/uploads/tmp directory
       move_uploaded_file($file['tmp_name'], $tmpFilePath);
 
+      $tmpFileMd5sum = md5_file($tmpFilePath);
+
       $resizedImage = QubitDigitalObject::resizeImage($tmpFilePath, 150, 150);
 
       if (0 < strlen($resizedImage))
@@ -65,6 +67,7 @@
       $uploadFiles[] = array(
         'name' => $file['name'],
         'tmpName' => $tmpFileName,
+        'md5sum' => $tmpFileMd5sum,
         'thumb' => $thumbName,
         'size' => hr_filesize($file['size'])
       );

Modified: trunk/web/js/multiFileUpload.js
==============================================================================
--- trunk/web/js/multiFileUpload.js     Tue Sep 15 17:04:27 2009        (r3331)
+++ trunk/web/js/multiFileUpload.js     Tue Sep 15 18:45:09 2009        (r3332)
@@ -72,8 +72,8 @@
 
       if (fileSize > maxUploadSize)
       {
-          oversizedFileList[oversizedFileList.length] = fileName;
-          uploader.removeFile(fileHash);
+        oversizedFileList[oversizedFileList.length] = fileName;
+        uploader.removeFile(fileHash);
       }
       else
       {
@@ -161,6 +161,13 @@
 
   for (i in uploadFiles)
   {
+    if ($('input[type=hidden][name*=md5sum][value=' + uploadFiles[i].md5sum + 
']').length)
+    {
+      $('div#upload-' + event['id']).remove();
+      showWarning('Warning: duplicate of ', event['id']);
+      continue;
+    }
+
     var thumbnail = '<img src="' + uploadTmpDir + '/' + uploadFiles[i].thumb + 
'"/>';
     $('#thumbnail-' + event['id']).html(thumbnail);
 
@@ -169,12 +176,9 @@
       return $(this).attr('style') + '; min-height: 100px';
     });
 
-    // Get the file index from the id passed by YUI
-    var fileIndex = event['id'].match(/([0-9]+)$/).shift();
-    if (null == fileIndex || isNaN(parseInt(fileIndex)))
-    {
-      fileIndex = i;
-    }
+    // Get the file index counting objects already uploaded
+    var lastInputName = $('input[type=hidden][name*=files]').attr("name");
+    fileIndex = lastInputName ? 
parseInt(lastInputName.match(/[0-9]+/).shift()) + 1 : 0;
 
     // Add 1 to the index to give a value > 0 and pad with a zero if < 10
     fileCounter = parseInt(fileIndex) + 1;
@@ -185,6 +189,7 @@
 
     // Write upload file data
     var hiddenFields = '<input type="hidden" name="files[' + fileIndex + 
'][name]" value="' + uploadFiles[i].name + '" />';
+    hiddenFields += '<input type=\"hidden\" name=files[' + fileIndex + 
'][md5sum]" value="' + uploadFiles[i].md5sum + '" />';
     hiddenFields += '<input type="hidden" name="files[' + fileIndex + 
'][tmpName]" value="' + uploadFiles[i].tmpName + '" />';
     hiddenFields += '<input type="hidden" name="files[' + fileIndex + 
'][thumb]" value="' + uploadFiles[i].thumb + '" />';
     $('#uploadForm').append(hiddenFields);
@@ -226,4 +231,15 @@
   }
 
   return fileName;
+}
+
+function showWarning(msg, id)
+{
+  var warning = '<ul id=\"warning_' + id + '\" class=\"validation_error\" 
style=\"margin-bottom: 12px; display: none;\">';
+  warning += '<li>' + msg + '</li>';
+  warning += '<ul>';
+
+  $('div#uploads').before(warning);
+
+  $('ul#warning_' + id).show();
 }
\ No newline at end of file

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to