? filefield-preview.patch
Index: filefield.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/filefield/filefield.module,v
retrieving revision 1.23
diff -u -r1.23 filefield.module
--- filefield.module	30 Mar 2007 03:20:24 -0000	1.23
+++ filefield.module	19 Apr 2007 08:33:09 -0000
@@ -10,7 +10,7 @@
  */
 
 
-function filefield_menu($maycache) {
+function filefield_menu($may_cache) {
   $items = array();
 
   if (!$may_cache && $_SESSION['filefield']) {
@@ -319,11 +319,19 @@
       return FALSE;
     }
 
-
     // let modules massage act on the file.
     module_invoke_all('filefield', 'file_prepare', $node, $field, $file);
 
-    $filepath = file_create_filename($file['filename'], file_create_path());
+    // Create the filepath for the preview
+    if (function_exists('token_replace')) {
+      // use tokenized paths if token module is installed.
+      global $user;
+      $filepath = file_create_filename($file['filename'], file_create_path(token_replace($field['widget']['file_path'], 'user', $user)));
+    }
+    else {
+      $filepath = file_create_filename($file['filename'], file_create_path($field['widget']['file_path']));
+    }
+
     if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
       if (strpos($filepath, file_directory_path()) !== FALSE) {
         $filepath = trim(substr($filepath, strlen(file_directory_path())), '\\/');
@@ -415,10 +423,10 @@
     '#value' => theme('filefield_icon', $file),
   );
 
-  $filepath = $file['fid'] == 'upload' ? file_create_filename($file['filename'], file_create_path()) : $file['filepath'];      
-
+  $filepath = $file['fid'] == 'upload' ? $file['preview'] : $file['filepath'];      
   $url = file_create_url($filepath);      
   $url = "<small>". check_plain($url) ."</small>";
+
   $form['description'] = array(
       '#type' => 'textfield', 
       '#default_value' => (strlen($file['description'])) ? $file['description'] : $file['filename'], '#maxlength' => 256, 
