diff -urp uploadpath_5.x/uploadpath.info uploadpath_6.x/uploadpath.info
--- uploadpath_5.x/uploadpath.info	2008-07-24 16:55:14.000000000 +0700
+++ uploadpath_6.x/uploadpath.info	2008-09-04 01:30:10.000000000 +0700
@@ -1,10 +1,6 @@
-; $Id: uploadpath.info,v 1.1.2.1 2007/06/15 22:44:39 crell Exp $
+; $Id: $
 name = Upload path
 description = Organize uploaded files according to admin-specified rules.
-dependencies = upload token
-
-; Information added by drupal.org packaging script on 2008-07-24
-version = "5.x-1.1"
-project = "uploadpath"
-datestamp = "1216893314"
-
+core = 6.x
+dependencies[] = upload
+dependencies[] = token
\ No newline at end of file
diff -urp uploadpath_5.x/uploadpath.module uploadpath_6.x/uploadpath.module
--- uploadpath_5.x/uploadpath.module	2008-07-24 15:43:37.000000000 +0700
+++ uploadpath_6.x/uploadpath.module	2008-09-04 02:14:44.000000000 +0700
@@ -1,5 +1,5 @@
 <?php
-// $Id: uploadpath.module,v 1.1.2.5 2008/07/24 08:43:37 davidwhthomas Exp $
+// $Id: uploadpath.module $
 
 /**
  * @file
@@ -9,20 +9,17 @@
 /**
  * Implementation of hook_menu().
  */
-function uploadpath_menu($may_cache) {
+function uploadpath_menu() {
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/uploadpath',
-      'title' => t('File upload paths'),
-      'description' => t('Configure a prefix to apply to the path of uploaded files.'),
-      'access' => user_access('administer site configuration'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('uploadpath_admin_settings'),
-      'type' => MENU_NORMAL_ITEM,
-    );
-  }
+  $items['admin/settings/uploadpath'] = array(
+    'title' => 'File upload paths',
+    'description' => 'Configure a prefix to apply to the path of uploaded files.',
+    'access arguments' => array('administer site configuration'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uploadpath_admin_settings'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
   return $items;
 }
@@ -132,11 +129,16 @@ function uploadpath_admin_settings() {
  */
 function uploadpath_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
-    case 'submit':
+    case 'insert':
+    case 'update':
       if(!in_array($node->type, variable_get('uploadpath_excluded_node_types',array()))){
-	      if (isset($node->files)) {
-	        foreach ($node->files as $key => $file) {
-	          if (0 === strpos($key, 'upload_')) {  // Only rewrite the name when adding the file, not when updating it
+        if (user_access('upload files')) {
+          if (isset($node->files)) {
+            foreach ($node->files as $key => $file) {
+              if($file['remove']){
+                // file is slated to be deleted
+                continue;
+              }
 	          //drupal_set_message('<pre>BEFORE'.print_r($node->files[$key],1).'</pre>');
 
 	            //optional 
@@ -177,26 +179,35 @@ function uploadpath_nodeapi(&$node, $op,
                   $file_name = $file_path . $file_name;
                 }else{
                   // apply new, prefixed file name by token replacing the path pattern
-                  $file_name = str_replace(array(' ', "\n", "\t"), '_', token_replace($pattern . '/', 'node', $node)) . $node->files[$key]['filename'];                      
+                  $tokenized = token_replace(variable_get('uploadpath_prefix', '') . '/', 'node', $node);
+                  $tokenized = str_replace(array(' ', "\n", "\t"), '_', $tokenized);
+                  $file_name = $tokenized . $file['filename'];
                 }
                 // SECURITY NOTE:
                 // Tokens include user supplied information and could provide an attack vector.
                 // The current method of creating directories prevents the use of .. or other malicious
                 // paths, but future developers should keep this in mind when modifying the following code	
-	            // Create the directory if it doesn't exist yet.
-	            $dirs = explode('/', dirname($file_name));
-	            $directory = file_directory_path();
-	            while (count($dirs)) {
-	              $directory .= '/' . array_shift($dirs);
-	              file_check_directory($directory, FILE_CREATE_DIRECTORY);
-	            }
-	            // Change where the file will be saved to the specified directory.
-	            $node->files[$key]['filename'] = $file_name;
-                //drupal_set_message('<pre>AFTER:'.print_r($node->files[$key],1).'</pre>');
+              // see if we need to move it, or if it's already ok
+              if($file['filepath'] != file_directory_path() . '/' . $file_name){
+	              // Create the directory if it doesn't exist yet.
+	              $dirs = explode('/', dirname($file_name));
+	              $directory = file_directory_path();
+	              while (count($dirs)) {
+	                $directory .= '/' . array_shift($dirs);
+	                file_check_directory($directory, FILE_CREATE_DIRECTORY);
+	              }
+                // move file on filesystem
+                if (file_move($file['filepath'], $file_name, FILE_EXISTS_RENAME)) {
+                  $node->files[$key] = $file_name;
+
+                  // update existing file in database
+                  db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $file['filepath'], $file['fid']);
+                }
+              }
 	          }
 	        }
 	      }
-       }
+      }
       break;
   }
 }
