Index: taxonomy_image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_image/taxonomy_image.module,v
retrieving revision 1.12.4.13.2.39
diff -u -r1.12.4.13.2.39 taxonomy_image.module
--- taxonomy_image.module	14 Mar 2009 14:47:43 -0000	1.12.4.13.2.39
+++ taxonomy_image.module	15 Mar 2009 14:50:09 -0000
@@ -613,10 +613,13 @@
   switch ($op) {
     case 'insert':
     case 'update':
-
+      // Check (and eventually create) category picture directory.
       $directory = file_create_path(variable_get('taxonomy_image_path', 'category_pictures'));
-      file_check_directory($directory, FILE_CREATE_DIRECTORY);
-      
+      if (!file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
+        drupal_set_message(t('Error creating the category picture directory: "%dir" does not exists, or is not writable.', array('%dir' => $directory)), 'error');
+        return;
+      }
+
       // Did they mark it to delete?
       if ($form_values['taxonomy_image_current_image_delete'] == TRUE) {
         taxonomy_image_delete($tid);
@@ -636,32 +639,23 @@
           drupal_set_message(t('Copy from @source to @where failed.', array('@source' => $source, '@where' => $where)), 'error');
         }      
       }
-      // Use upload field
+      // Upload field used?
       else {
         $validators = array();
         // FILE_EXISTS_REPLACE allows multiple terms to use the same image without having multiple files.      
         $file = file_save_upload('taxonomy_image_upload', $validators, $directory, FILE_EXISTS_REPLACE);
-        // New file to upload?
-        if (!$file) {
-          break; // No, just go on our way.
-        }
 
-        if(is_object($file)) {
-          // Make sure Cron doesn't delete this file.
-          file_set_status($file, FILE_STATUS_PERMANENT);
+        if (is_object($file)) {
+          // If no errors while uploading, save term-image relation into DB
           $filepath = variable_get('taxonomy_image_path', 'category_pictures') . '/' . $file->filename;
           
-          if (taxonomy_image_add($tid, $file->filename))
+          if (taxonomy_image_add($tid, $file->filename)) {
+            // Successfully added to DB, make sure Cron doesn't delete this file.
+            file_set_status($file, FILE_STATUS_PERMANENT);
             drupal_set_message(t('Image uploaded as @name.', array('@name' => $filepath)));
+          }
           else
-            drupal_set_message(t('Database insert failed. [tid = !tid, path = @path.', array('!tid' => $tid, '@path' => $filepath)), 'error');
-        }
-        elseif (!file_check_directory($directory)) {
-          // We know what's wrong, so generate a more useful error message.
-          drupal_set_message(t('The category picture directory "%dir" does not exist, or is not writable.', array('%dir' => $directory)), 'error');
-        }
-        else {
-          drupal_set_message(t('Image upload failed.'), 'error');
+            drupal_set_message(t('Error while adding image [tid = !tid, path = @path].', array('!tid' => $tid, '@path' => $filepath)), 'error');
         }
       }
       break;
@@ -670,6 +664,7 @@
       break;
   }
 }
+
 /**
  * Helper function for adding an image to a term
  */

