Freebies and Downloads in Drupal 6: Part1

Mark Noble

November 2009

Free content is a fantastic way of building customer loyalty. Depending on the content that you provide, you can also keep your brand in front of people. For example, a simple tastefully-done screen saver or desktop background can be used to always keep your logo on your customers' desktop. Of course, you need to make sure that the free content is of the highest possible quality to ensure that the customers will actually use the content.

Many visitors want to print content or save it to their computers for later use when they are not online or are not working on their computers. We will build PDF files automatically, to give your visitors this convenience.

If you allow visitors to download content from your site, you need to be careful that your site security is solid, so that an unscrupulous user cannot download content that you don't want them to have access to. We will discuss how to protect your content in this article.

Adding downloads and PDFs to the web site

In this section, we will discuss how to add downloads and PDFs to the web site.

Controlling how files are downloaded

Good Eatin' Goal: Ensure that Drupal has full control over any files that are uploaded, so that we can specify who can download the files.

Additional modules needed: None

Basic steps

Drupal allows you to set downloads to either Public or Private. The public setting does not have any additional download security. The private setting allows Drupal to secure and manage the downloaded files.

You can control this functionality using the File system settings, which are available by selecting Site configuration and then File system, from the Administer menu, as shown in the following screenshot:

Freebies and Downloads in Drupal 6

Because we want Drupal to provide additional security for the downloaded files, we will select the Private setting and then save the configuration.

You can also control where the files are stored on the web site, and also specify a temporary location to be used while files are being transferred. In most cases, the defaults are acceptable. However, you may need to customize the directories depending on how your server and site are configured. If you are using the private download method, the File system path should not be accessible via a web browser. To ensure that a directory is not available via a web browser, you should choose a folder that is not located within the Drupal installation. It should also not be located within your root web folder. On most systems, the root web folder is named htdocs. If you are unsure what your root web folder is, ask your webhost. Some hosting companies do not allow you to create folders outside the root web folder. If this is the case, you can contact your host to see if they can make an exception, or you will have to use the public download method.

Allowing files to be uploaded to the web site

Good Eatin' Goal: Allow authorized users to upload a file to the web site.

Additional modules needed: Upload (core).


Basic steps

In order to allow a user to download a file, you must first upload files to the web site. We will create a downloads page that stores all of the files that have been uploaded.


  1. Begin by activating the Upload module, which is a part of the core Drupal distribution.
  2. {literal}

  3. We can now customize the permissions for the Upload module by clicking on User management and then on Permission. The available permissions are shown in the following screenshot:

    Freebies and Downloads in Drupal 6

    It is a good idea to give only authenticated users the ability to view and download files. This will provide an additional incentive for visitors to register on your web site.

  4. We can now build a new page for our uploaded files by clicking on Create content and then on Page.
  5. The basic information for the page is shown below:

    Freebies and Downloads in Drupal 6

  6. To add a file to the page, expand the File attachments section. The section appears as follows:

    Freebies and Downloads in Drupal 6

  7. You can now Browse for the file to be uploaded, and then once you have selected it, click Attach.
  8. After a file has been attached, it will be listed on the form as shown below:
  9. Freebies and Downloads in Drupal 6

  10. After you save the new page, users with the appropriate permissions will be able to download the file by clicking on the link. You can also add links within the text of a page.

    Sending the correct file types to a user

    Good Eatin' Goal: Ensure that the correct file type is sent to the browser so that the visitor's computer can accurately determine how to handle it.

    Additional modules needed: File MIME (

    Basic steps

    As you add files to your site for download, it is important to make sure that a visitor's browser knows how to display the file. With web sites, this is done by setting the MIME type for the file. Some common MIME types are:

  11. text/html: A standard web page
  12. text/csv: A comma-delimited file
  13. text/plain: Plain text with no formatting
  14. audio/mpeg: Audio mpeg1 and mpeg2 files
  15. audio/mp4: Audio mp4 files
  16. image/jpeg: JPEG encoded image files
  17. image/gif: GIF encoded images
  18. application/pdf: A PDF document
  19. application/javascript: A script file written in Javascript

A full list of how Drupal handles each file type can be found at:

The File MIME module automatically detects the type of file based on the file extension, and sets the appropriate MIME type, which is returned to the browser.

To use the File MIME module, carry out the following steps:


  1. Download, install, and activate the File MIME module.
  2. Configure the module by selecting Site configuration and then File MIME, from the Administer menu. The module allows you to specify the location of the mime.types file, which is installed along with your web server. The Apache web server installs this file in the same directory as where your httpd.conf file is installed.
  3. Freebies and Downloads in Drupal 6

  4. You can also add additional mappings for specific file types. For example, you may want .CSV files to be treated as Microsoft Excel files if you know that a significant number of your users are running Windows-based machines and want to download .CSV files into Excel. You can do this by adding the following line to the settings, as shown in the preceding screenshot:
  5. application/ csv xls.
  6. After the module has been properly configured, the module will automatically set the correct MIME types each time that a file is downloaded.

Forcing a file to be downloaded

Good Eatin' Goal: Force a file to be downloaded even if it could be displayed within the browser.

Additional modules needed: File Force (

Basic steps

In the previous section, we discussed setting the MIME type automatically so that the browser can handle the file correctly. However in some cases, you may want the file to always be saved to the user's computer, even if it is a common file type that can be read by the browser. For example, you may want to have PDF files or pictures to be downloaded to the customer's computer even though all modern browsers can display these types of files in the browser.

To use the File Force module, download, install, and activate it.

The File Force module does not require any configuration, so you can begin using it immediately. To use the File Force module, you simply need to prefix any link to downloadable content with the text download. So, if you have a link called: /sites/default/files/song.mp3 that you want users to always download, you would replace the link with /download/sites/default/files/song.mp3. File Force will then modify the information returned to the browser to indicate that the file should be downloaded rather than be displayed or played.

If you do not add the download prefix to the link, the File Force module will not change the behavior of downloads, so you can offer files either as downloads or as play-now links.

Tracking download counts

Good Eatin' Goal: Track how many downloads have been completed, so that we can gauge the effectiveness of our promotions.

Additional modules needed: Download Count (

Basic steps

If you want to be able to determine the effectiveness of your downloads, you should track how many times each file has been downloaded. The Download Count module is specifically designed to help you with this.

  1. To begin with, download and install the Download Count module.
  2. The Download counter can be configured by selecting Site configuration and then Download counter, from the Administer menu.
  3. The most important configuration is defining which file extensions should be included in the download counter, and which should be ignored.

    Freebies and Downloads in Drupal 6

    Depending on how your site is configured, you may want to either add or remove extensions from the list of extensions to be excluded from the statistics.

  4. You can also configure whether or not download counters are displayed to the administrator, and you can also add more information to the statistics page, which is available at These options are shown in the following screenshot:
  5. Freebies and Downloads in Drupal 6

  6. You can also configure the download count permissions by selecting User management and then Permissions from the Administer menu. The available permissions are shown in the following screenshot:
  7. Freebies and Downloads in Drupal 6

  8. The download count for a single page appears as follows:

    Freebies and Downloads in Drupal 6

    As you can see, this page shows the number of times each file has been downloaded, and when it was last downloaded.

  9. You can also view statistics for all downloadable files by navigating to The resulting page is formatted as follows:

    Freebies and Downloads in Drupal 6

    This page shows all of the files that have been downloaded, regardless of the page they are on, and you can also sort the files depending on your needs.

    Allow users to browse files

    Good Eatin' Goal: Give users an intuitive interface to see which files are available for download, with additional information for each file.

    Additional modules needed: Filebrowser (

    Basic steps

    The filebrowser module allows visitors to easily browse downloadable files on your site.

  10. Begin by downloading and installing the filebrowser module
  11. In order to display a list of files in a directory, we need to create a Directory Listing page. To do this, first select Create content and then Directory listing from the Navigation menu.
  12. Enter a title for the page, and specify the directory you wish to browse, as shown in the following screenshot:

    Freebies and Downloads in Drupal 6

  13. After you are happy with the settings, save the page. When you view the page, you will see a listing of the files in the directory as well as summary information for the directory, as shown in the following screenshot:

    Freebies and Downloads in Drupal 6

  14. Clicking on a filename will open the file in the browser, and clicking on a directory will open that directory.
  15. The filebrowser module offers a variety of permissions that give you control over who can create directory listings, and who can edit and delete directory listings.

    Freebies and Downloads in Drupal 6

    You may want to only allow authenticated users to view directory listings, in order to provide an additional incentive for registration.

>> Continue Reading Freebies and Downloads in Drupal 6: Part 2

[ 1 | 2 ]

If you have read this article you may be interested to view :

You've been reading an excerpt of:

Drupal 6 Site Builder Solutions

Explore Title