[Jaws-commits] r13264 - branches/0.8/html/include/Jaws

afz at jaws-project.com afz at jaws-project.com
Sat Aug 4 21:25:58 UTC 2012


Author: afz
Date: 2012-08-04 21:25:57 +0000 (Sat, 04 Aug 2012)
New Revision: 13264

Modified:
   branches/0.8/html/include/Jaws/Utils.php
Log:
[UploadFile]: html5 multiple file upload supported

Modified: branches/0.8/html/include/Jaws/Utils.php
===================================================================
--- branches/0.8/html/include/Jaws/Utils.php	2012-08-04 18:51:23 UTC (rev 13263)
+++ branches/0.8/html/include/Jaws/Utils.php	2012-08-04 21:25:57 UTC (rev 13264)
@@ -323,67 +323,81 @@
         }
 
         $result = array();
-        if (isset($files['name'])) {
+        if (isset($files['tmp_name'])) {
             $files = array($files);
         }
 
         $dest = rtrim($dest, "\\/"). DIRECTORY_SEPARATOR;
         $allowFormats = array_filter(explode(',', $allowFormats));
         $denyFormats  = array_filter(explode(',', $denyFormats));
-        foreach($files as $key => $file) {
-            if (empty($file['tmp_name'])) {
-                continue;
+        foreach($files as $key => $listFiles) {
+            if (!is_array($listFiles['tmp_name'])) {
+                $listFiles = array_map(create_function('$item','return array($item);'), $listFiles);
             }
 
-            $filename = isset($file['name']) ? $file['name'] : '';
-            if (isset($file['error']) && !empty($file['error'])) {
-                return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_'.$file['error']),
-                                      __FUNCTION__);
-            }
+            for($i=0; $i < count($listFiles['name']); ++$i) {
+                $file = array();
+                $file['name']     = $listFiles['name'][$i];
+                $file['tmp_name'] = $listFiles['tmp_name'][$i];
+                $file['size']     = $listFiles['size'][$i];
+                if (isset($listFiles['error'])) {
+                    $file['error']    = $listFiles['error'][$i];
+                }
 
-            $filename = strtolower(preg_replace("/[^[:alnum:]_\.-]*/i", "", $filename));
-            $fileinfo = pathinfo($filename);
-            if (isset($fileinfo['extension']) && !empty($fileinfo['extension'])) {
-                if (in_array($fileinfo['extension'], $denyFormats) ||
-                   (!empty($allowFormats) && !in_array($fileinfo['extension'], $allowFormats)))
-                {
-                    return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $filename),
+                if (empty($file['tmp_name'])) {
+                    continue;
+                }
+
+                $filename = isset($file['name']) ? $file['name'] : '';
+                if (isset($file['error']) && !empty($file['error'])) {
+                    return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_'.$file['error']),
                                           __FUNCTION__);
                 }
-            }
 
-            if (empty($fileinfo['filename']) || (!$overwrite && file_exists($dest . $filename))) {
-                $filename = time() . '_' . $filename;
-            }
-            $uploadfile = $dest . $filename;
+                $filename = strtolower(preg_replace("/[^[:alnum:]_\.-]*/i", "", $filename));
+                $fileinfo = pathinfo($filename);
+                if (isset($fileinfo['extension']) && !empty($fileinfo['extension'])) {
+                    if (in_array($fileinfo['extension'], $denyFormats) ||
+                       (!empty($allowFormats) && !in_array($fileinfo['extension'], $allowFormats)))
+                    {
+                        return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $filename),
+                                              __FUNCTION__);
+                    }
+                }
 
-            if (is_uploaded_file($file['tmp_name'])) {
-                if (!move_uploaded_file($file['tmp_name'], $uploadfile)) {
-                    return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $filename),
-                                          __FUNCTION__);
+                if (empty($fileinfo['filename']) || (!$overwrite && file_exists($dest . $filename))) {
+                    $filename = time() . '_' . $filename;
                 }
-            } else {
-                // On windows-systems we can't rename a file to an existing destination,
-                // So we first delete destination file
-                if (file_exists($uploadfile)) {
+                $uploadfile = $dest . $filename;
+
+                if (is_uploaded_file($file['tmp_name'])) {
+                    if (!move_uploaded_file($file['tmp_name'], $uploadfile)) {
+                        return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $filename),
+                                              __FUNCTION__);
+                    }
+                } else {
+                    // On windows-systems we can't rename a file to an existing destination,
+                    // So we first delete destination file
+                    if (file_exists($uploadfile)) {
+                        @unlink($uploadfile);
+                    }
+                    $res = $move_files? @rename($file['tmp_name'], $uploadfile) : @copy($file['tmp_name'], $uploadfile);
+                    if (!$res) {
+                        return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $filename),
+                                              __FUNCTION__);
+                    }
+                }
+
+                // Check if the file has been altered or is corrupted
+                if (filesize($uploadfile) != $file['size']) {
                     @unlink($uploadfile);
+                    return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_CORRUPTED', $filename),
+                                             __FUNCTION__);
                 }
-                $res = $move_files? @rename($file['tmp_name'], $uploadfile) : @copy($file['tmp_name'], $uploadfile);
-                if (!$res) {
-                    return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $filename),
-                                          __FUNCTION__);
-                }
-            }
 
-            // Check if the file has been altered or is corrupted
-            if (filesize($uploadfile) != $file['size']) {
-                @unlink($uploadfile);
-                return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_CORRUPTED', $filename),
-                                         __FUNCTION__);
+                Jaws_Utils::chmod($uploadfile);
+                $result[$key][$i] = $filename;
             }
-
-            Jaws_Utils::chmod($uploadfile);
-            $result[$key] = $filename;
         }
 
         return $result;



More information about the Jaws-commits mailing list