I have a custom content type which allows one file to be attached to it. In the teaser of the node I want to fine-print the date of the file's (rather than node's) last modification and its size. How can I access those properties in a suggestion template file or in the field-based View that generates the list of teasers?

I am using Drupal 7, and version 7.x-3 of the Views module.

1 Answer 1


Partial answer, but in the views settings page, you add a relationship to the field that holds the file. Then, when you add a field, you should see an option for File: Size in the list. Other fields for file into appear, but mtime isn't one of them.

A hackish way to get mtime is to use stat in your view template, but I would do that as a last resort if you can't find a module to add this as a view field.

  • Thanks, partial answer but a very mind-opening one. Thank you! I will try to submit a feat request for views so that they add modification date through a relationship. Nov 30, 2011 at 10:38
  • The problem is that mtime, along with a lot of other file information, isn't stored in the database. A module would have to scan the files, store it in a table, and then expose the data to views.
    – mpdonadio
    Nov 30, 2011 at 13:32
  • Now that I have attempted to write code, I understand why you called stat a last resort. I could not find a way to convert remote link (http) into a local path (file system path) which is needed as a stat parameter. Dec 3, 2011 at 14:47
  • You need to get DOCUMENT_ROOT. Read the comments on api.drupal.org/api/drupal/includes--common.inc/function/…. But I think you can also do all of it through D7 File API.
    – mpdonadio
    Dec 3, 2011 at 14:59

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.