--- /home/user01/uploadpath/uploadpath.module	2008-09-08 13:50:02.000000000 +0530
+++ ./uploadpath.module	2008-12-12 18:10:48.000000000 +0530
@@ -78,6 +78,32 @@
               $directory .= '/' . array_shift($dirs);
               file_check_directory($directory, FILE_CREATE_DIRECTORY);
             }
+            
+            /**
+             * Added by Zyxware to control file naming also
+             * Currently this conflicts with Cleaning File name upload
+             * We cannot use both features at once.
+             */
+            // Only rename new files to be saved
+            if ($file['new'] && !$file['remove']){
+              //Get patterns for naming files if any
+              $filename_pattern = variable_get('uploadfiles_pattern_'.$node->type, false);
+              if(!$filename_pattern){ 
+                //default pattern
+                $filename_pattern = variable_get('uploadfiles_pattern', '');
+              }
+              
+              //rename only if the filename_pattern is set otherwise
+              //preserve the original name
+              if (strlen($filename_pattern) != 0) {
+                
+                $new_file_name = str_replace(array(' ', "\n", "\t"), '_', trim(token_replace($filename_pattern, 'node', $node)));
+                $extension = pathinfo($file['filename'], PATHINFO_EXTENSION);
+                $file_name = dirname($file_name).'/'.$new_file_name. '.' .$extension;      
+              }
+            }
+            //Addition Ends
+            
             //move file to new subfolder
             if (file_move($file['filepath'], $file_name, FILE_EXISTS_RENAME)) {
               //update node file array with new path, if needed
