In PHP 5.1 and lower, the [filefield-onlyname-original] token doesn't work since the PHP pathinfo() function doesn't set a value for 'filename' in its returned array. Possible patch below:

--- /nfs/home/D/dwong/filefield_paths.module	2009-07-09 16:29:43.432792000 -0400
+++ filefield_paths.module	2009-07-09 16:32:11.200918000 -0400
@@ -645,7 +645,13 @@ function filefield_paths_token_values($t
     if (!empty($object[0]['origname'])) {
       $orig = pathinfo($object[0]['origname']);
     }
-    $tokens['filefield-onlyname-original'] = $orig['filename'];
+    if (!isset($orig['filename'])) { 
+      // < PHP 5.2
+      $tokens['filefield-onlyname-original'] = substr($object[0]['filename'], 0, strpos($object[0]['filename'], '.'));
+    } 
+    else { 
+      $tokens['filefield-onlyname-original'] = $orig['filename'];
+    }
     $tokens['filefield-extension-original'] = $orig['extension'];
     return $tokens;
   }

Comments

Deciphered’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Status: Active » Fixed

Hi dwong127,

Thanks for picking up on that one.
I had to make some changes to the code as it was only grabbing the current filename, not the original filename, but it has been fixed and committed to DRUPAL-5 and DRUPAL-6--1.

Dev release should be available in about two hours or so.

Cheers,
Deciphered.

Deciphered’s picture

Status: Fixed » Closed (fixed)
sp3boy’s picture

Status: Closed (fixed) » Active

Sorry to be a real pain, but hopefully there is a quick answer to this which (despite spending some hours searching) I've missed:

The {files}.origname column is added by Filefield_paths, yes?
It is referenced in filefield_paths_token_values(), (as seen in the patch above)?

Where is it loaded to the node object? As far as I can see (having done some step-by-step debugging in Eclipse) it is not populated on the $object[0]. So any re-creation of a filepath or filename from the original filename will not know the original name and fall back on the current (possibly post-tokenised) filename?

sp3boy’s picture

Status: Active » Closed (fixed)

Ha, I was indeed being a pain! After some more hours of testing Image with Filefield_paths I have found why Uploaded files have the "origname" node property populated on load but Images don't - upload_load() performs a SELECT * on {files} which pulls in the column. image_load() only takes specific columns from {files}.

Now I just need to figure out what should be done in Image...

Deciphered’s picture

HI sp3boy,

Sorry I didn't reply, but I really haven't been able to give much time to my Drupal projects of late.
I did see this issue, but I wanted to just confirm it before responding, but you are absolutely correct, it isn't FileField Paths that reads in the column.

If you are unable to fix the issue on Image's side, it would be possible to make a Image module specific change to fix this in the modules/image.inc file of FileField Paths.

Let me know how you go.

Cheers,
Deciphered.

emok’s picture

Status: Closed (fixed) » Active

Back to the original issue: It is not just filefield-onlyname-original that needs fixing. Also a few lines up where filefield-onlyname is set you need to handle the quirks of old PHP versions. In filefield_paths_token_values(), I suggest you change

    $item = pathinfo($object[0]['filename']);

into

    $item = pathinfo($object[0]['filename']);
    if (empty($item['filename'])) { // The 'filename' did not exist before PHP 5.2.0
      $item['filename'] = basename($item['basename'], '.'. $item['extension']);
    }
Deciphered’s picture

Emok,

You're absolutely correct, oversight on my behalf. That's why I don't like fixing issues that I can't reproduce.
Will fix shortly.

Cheers,
Deciphered.

Deciphered’s picture

Status: Active » Fixed

This has been committed and is available in 6.x-1.4.

Cheers,
Deciphered.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.