To reproduce (filefield 6.x-3.10, imagefield 6.x-3.10, insert 6.x-1.1, filefield_paths 6.x-1.4):
1. Set 'Number of values' to 'Unlimited', pattern for 'File name' as '[nid].[filefield-extension-original]', 'File Path' to fixed dir (don't use patterns)
2. Create new node
3. Attach two images (do not save)
4. Insert them into node body
5. Save node

Result:
In {files} table all is ok (that's why if you save node after step 3, and insert on subsequent edit, it will work):
filename|filepath
596.jpg|files/fixeddir/596.jpg
596.jpg|files/fixeddir/596_0.jpg

but the references in body are both set to first file ('files/fixeddir/596.jpg')

Cause:
filefield_paths_file_move() uses file_move($file['field']['filepath'], $dest . '/' . $file['filename']['new'], $replace) ($replace = FILE_EXISTS_RENAME). In case there already was a file with specified name in destination folder, it is renamed and the resulting filepath gets returned in first argument, so after this call it's in $file['field']['filepath'], and the code updating {files} table uses that, but after returning to filefield_paths_filefield_paths_process_file() the code responsible for fixing references doesn't:

$file['filepath']['new'] = str_replace($file['filename']['old'], $file['filename']['new'], $file['filepath']['new'])

which later is used as replacement in regex:

          $pattern = array(
            // ...
            'replace' => $file_directory_path . '$1' . str_replace(file_directory_path(), '', $file['filepath']['new']),
          );
CommentFileSizeAuthor
filefield_paths.module-ref-fix.patch688 bytestacituseu

Comments

deciphered’s picture

Status: Needs review » Closed (won't fix)

No longer supporting Drupal 6 issues for this module.