Setting up a content type with a file field

Last modified: September 8, 2009 - 20:10

Here are the basic steps for setting up a content type with a FileField field. For this example, I am going to show you how to add a field into a Story node.

  1. Go to Administer → Content Types (/admin/content/types)
  2. For the Story node type, click on Manage Fields
  3. Add a new field by selecting (i) a label, (ii) a machine-name for your field, (iii) data type of File, and a form element of File Upload. Click Save. (see Figure 1)
  4. You will enter the "settings" page for your new file type. Enter the file extenstions you wish to allow, file size limits, and so on. Check the "Required" box if you want to require your users to upload a file for all Story nodes. "Number of Values" can be used if you want to allow your users to upload more than one file into this Story node. Click Save Field Settings.
  5. You return to the Manage Fields administration page. Click on the Display Fields tab at the top. Here, you can choose if you want to display your field label. Choose Generic Files if you want to display a small icon and the file name when viewing the node’s teaser and full-node display.

For an example, let’s create a table with all Story nodes that have files, a link to the file, and the file size. With Views, you can easily do this.

  1. Go to Administer → Site Building → Views (/admin/content/types)
  2. Click on the Add tab. Provide a view name for a "Node" view. Click Next
  3. Change the default settings as follows (see Figure 2):
    • Style: Table
    • Filters:
      Node: Published=Yes
      Node: Type = Story
      Content: File Attachments (field_file_attachments) – list = True
    • Relationships:
      Content: File Attachments (field_file_attachments) - fid
    • Fields:
      Node: Title
      Content: File Attachments (field_file_attachments) (Use the Generic Files fomat)
      File: Size (use the File Attachments relationship)

(There are few screenshots here: #552912: Documentation for "Setting up a content type with a FileField field". I will post them here once I get permission #559278: Request to be a member of doc team.)

 
 

Drupal is a registered trademark of Dries Buytaert.