Users will upload files. The user will tag the file with a project name and some keywords and an optional text comment. I have made a content-type called 'image', that has filed for title, file, project, keywords and comments.

I want the tile of the node to be the name of the uploaded file. The name of the filed is 'file' the field is of type File, the widget is of type File, and the filed name is field_file. I have the token module and the "Automatic Nodetitles" module. The token module gives me token "node:field_file_body", this is not the file name.

How do I set the title of the each "image" node to the name of the uploaded file?


4 Answers 4


I also battled with this; this is my solution:

Use the Automatic Nodetitles Module as described by the others, and in the Pattern for the title text box load up the filefield and extract the filename that way. Example:

//Load the file
$file = file_load($node->field_document['und'][0]['fid']);

// Filename
return $file->filename;

Obviously you need to check the Evaluate PHP in pattern. checkbox at the bottom for this to work, and replace "field_document" with the name of your own file field.

Hope this helps somebody!


You could try this module: FileField Paths. From the description, it looks like it might provide you with the tokens you need.

Edit Here's the code where it adds the tokens if you're interested: see the repository. If that's not what you need, it's probably pretty close to what you need.

Edit 2 Looks like you'll have to create a module. Don't stress, it's not hard. This blog post shows you how to create a module which provides custom tokens for nodes. You can combine that with the repository link in my first edit to acheive the token you need. If you've never created a module before, it's simple. Follow the simple tutorial on Drupal.org. All you need is a folder in sites/all/modules with the files mymodule.module and mymodule.info where "mymodule" is your module name.

  • I have FileField Paths module. There is no token for file_name or file_info just file_body. I am still learning how to modify drupal and am somewhat at a loss.
    – Joe
    Feb 7, 2012 at 21:26
  • I just added more info. I guess the "files" tokens are only available to fields. You need to add the token you need to the "node" area. Feb 7, 2012 at 22:53
  • Joe - Are you using Drupal 6 or 7 BTW? Yeah at any rate for this to work, you should be using CCK filefield upload for D6 and Fields file upload for D7. I don't think you need to create a module, see my answer below. I just tested Auto Nodetitles Module and sure enough the File was available as a token for Auto Nodetitles Feb 8, 2012 at 0:01

In addition to what @Jonathan Rowny said, you could also use the Automatic Nodetitles Module and then use the Token of the uploaded file name as the auto node title. But you will also need the Token module installed / activated. I have used this method and it works great.

Added: screen capture from Auto Nodetitles that can use a token name of the file name.

enter image description here

Token Replacement Patterns for Files

  • Where is the file name token? I look in the token lists for "Nodes" and all I can find is [node:field_file_body]. I have looked everywhere but not found anything with "file name". I am using Drupal 7.
    – Joe
    Feb 7, 2012 at 22:15
  • Whenever you use Token, you have "Replacement Patterns" contextual to where you are using tokens. See my screen capture I have added above. Feb 7, 2012 at 22:24
  • Arghh.... I am missing something very basic.
    – Joe
    Feb 8, 2012 at 13:06
  • Arghh.... I am missing something very basic. I am using Drupal 7 I have a filed named "file" that is of type "File" that has a MySQL filed name of "field_file" and a widget of type "File". I have modules "Token", "FileField Paths" and "Automaic NodeTitles". My first screen lokks just like yours but I never get a "Replacement Patterns" area. all I get is Name: File, Token: [node:filed_file_body], Description: File field . How do I amke Replacement Pattern appear? I never get anything like your second screen.
    – Joe
    Feb 8, 2012 at 13:18
  • Damn... How do I post an image to this site?
    – Joe
    Feb 8, 2012 at 13:28

I got it working with Automatic Nodetitles, Token, and Entity Token. I used the following token:


As you described in the question, I have a field called file in my nodetype. I believe the :file portion of the token was created by Entity Token.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.