/**
  * Take an array of files from a form post and copy them to the required directory
  * @param file_vars  - the $_FILES superglobal from a form post
  * @return array     - an array of file names that were uploaded
  */
 function uploadFiles($file_vars = "")
 {
     $util = FileUtility::current();
     // Get the asset group for the file
     $disp = Display::current();
     $asset_group = $disp->getValue('asset_group') . "/";
     if (!is_dir(FileUtility::UPLOAD_DIR . $asset_group)) {
         mkdir(FileUtility::UPLOAD_DIR . $asset_group);
     }
     if (!$util->uploadDone()) {
         if (!$file_vars) {
             $file_vars = $_FILES;
         }
         $pathinfo = pathinfo($file_vars['media_url']['name']);
         $extension = '.' . $pathinfo['extension'];
         $filename = $pathinfo['filename'];
         $ret = array();
         if (!empty($file_vars) && count($file_vars)) {
             foreach ($file_vars as $label => $file) {
                 // Set the filename to an md5 #
                 //$original_name = $file['name'];
                 //$file['name'] = md5($file['name']);
                 $file['name'] = str_replace(' ', '-', $filename);
                 while (file_exists(FileUtility::UPLOAD_DIR . $asset_group . $file['name'] . $extension)) {
                     $file['name'] = md5($file['name']);
                 }
                 $file['name'] = $file['name'] . $extension;
                 $error = ArrayUtility::getArrayValue($file, "error");
                 if (!$error) {
                     if (move_uploaded_file($file['tmp_name'], FileUtility::UPLOAD_DIR . $asset_group . $file['name'])) {
                         $ret[$label] = ArrayUtility::getArrayValue($file, 'name');
                     } else {
                         throw new Exception("Error uploading file " . FileUtility::UPLOAD_DIR . $asset_group . $file['name']);
                     }
                 }
             }
         }
         $util->setUploadedFiles($ret);
     } else {
         $ret = $util->uploadedFiles();
     }
     return $ret;
 }