4 min read

Adding and configuring file fields to content types

There are many cases where we need to attach files to website content. For instance, a restaurant owner might like to upload their latest menu in PDF format to their website, or a financial institution would like to upload a new product catalog so customers can download and print out the catalog if they need it.

The File module is built into the Drupal 7 core, which provides us with the ability to attach files to content easily, to decide the attachment display format, and also to manage file locations.

Furthermore, the File module is integrated with fields and provides a file field type, so we can easily attach files to content using the already discussed field system making the process of managing files much more streamlined.

Time for action – adding and configuring a file field to the Recipe content type

In this section, we will add a file field to the Recipe content type, which will allow files to be attached to Recipe content. Follow these steps:

  1. Click on the Structure link in the administration menu at the top of the page.

    Drupal 7 Fields/CCK: Using the File Field Modules

  2. The following page will display a list of options. Click on the Content types link to go to the Content types administration page.

    Drupal 7 Fields/CCK: Using the File Field Modules

  3. Since we want to add a file field to the Recipe content type, we will click on the manage fields link on the Recipe row as shown in the following screenshot:

    (Move the mouse over the image to enlarge it.)

  4. This page will display the existing fields of the Recipe content type. In the Label field enter “File”, and in the Field name field enter “file”. In the field type select list select File as the field type, the field widget will be automatically switched to File as the field widget. After the values are entered, click on Save.

    Drupal 7 Fields/CCK: Using the File Field Modules

  5. A new window will pop up which provides the field settings for the file field that we are creating. There are two checkboxes, and we will enable both these checkboxes. The last radio button option will be selected by default. Then click on the Save field settings button at the bottom of the page.

    Drupal 7 Fields/CCK: Using the File Field Modules

  6. We clicked on the Save field settings button to store the values for the file field settings that we selected. After that, it will direct us to the file field settings administration page, as in the following screenshot:

    Drupal 7 Fields/CCK: Using the File Field Modules

  7. We can leave the Label field as default as it will be filled automatically with the value we entered previously. We will also leave the Required field as default, because we do not want to force users to attach files to every recipe. In the Help text field, we can enter “Attach files to this recipe”.

    Drupal 7 Fields/CCK: Using the File Field Modules

  8. In the Allowed file extensions section, we can enter the file extensions that are allowed to be uploaded. In this case, we will enter “txt, pdf, zip”. In the File directory section, we can enter the name of a subdirectory that will store the uploaded files, and in this case, we will enter “recipe_files”:

    Drupal 7 Fields/CCK: Using the File Field Modules

  9. In the Maximum upload size section, we can enter a value to limit the file size when uploading files. We will enter “2MB” in this field. The Enable Description field checkbox allows users to enter a description about the uploaded files. In this case, we will enable this option, because we would like users to enter a description of the uploaded files.

    (Move the mouse over the image to enlarge it.)

  10. In the Progress indicator section, we can select which indicator will be used when uploading files. We select Throbber as the progress indicator for this field.

    (Move the mouse over the image to enlarge it.)

  11. You will notice the bottom part of the page is exactly same as in the previous section. We can ignore the bottom part and click on the Save settings button to store all the values we have entered.

    Drupal 7 Fields/CCK: Using the File Field Modules

  12. Drupal will direct us back to the manage fields administration page with a message saying we have successfully saved the configuration for the file field.

    Drupal 7 Fields/CCK: Using the File Field Modules

  13. After creating the file field, the file field row will be added to the table. This table will display the details about the file field we just created.

    (Move the mouse over the image to enlarge it.)

LEAVE A REPLY

Please enter your comment!
Please enter your name here