Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
In this article by Mark Noble, we will explore various ways of adding downloads to your web site to provide free content, or to deliver paid content to users. We will also discuss the automatic conversion of pages to PDF files, which your users can download to read or print.
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
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:
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).
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.
- Begin by activating the Upload module, which is a part of the core Drupal distribution.
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:
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.
- We can now build a new page for our uploaded files by clicking on Create content and then on Page.
- The basic information for the page is shown below:
- To add a file to the page, expand the File attachments section. The section appears as follows:
- You can now Browse for the file to be uploaded, and then once you have selected it, click Attach.
- After a file has been attached, it will be listed on the form as shown below:
- 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 (http://drupal.org/project/filemime).
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:
- text/html: A standard web page
- text/csv: A comma-delimited file
- text/plain: Plain text with no formatting
- audio/mpeg: Audio mpeg1 and mpeg2 files
- audio/mp4: Audio mp4 files
- image/jpeg: JPEG encoded image files
- image/gif: GIF encoded images
- application/pdf: A PDF document
A full list of how Drupal handles each file type can be found at: http://api.drupal.org/api/function/file_get_mimetype.
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:
- Download, install, and activate the File MIME module.
- 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.
- 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:
- After the module has been properly configured, the module will automatically set the correct MIME types each time that a file is downloaded.
application/vnd.ms-excel csv xls.
eBook Price: $26.99
Book Price: $44.99
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 (http://drupal.org/project/file_force).
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 (http://drupal.org/project/download_count).
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.
- To begin with, download and install the Download Count module.
- The Download counter can be configured by selecting Site configuration and then Download counter, from the Administer menu.
The most important configuration is defining which file extensions should be included in the download counter, and which should be ignored.
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.
- 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 yoursite.com/download_counter. These options are shown in the following screenshot:
- 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:
The download count for a single page appears as follows:
As you can see, this page shows the number of times each file has been downloaded, and when it was last downloaded.
You can also view statistics for all downloadable files by navigating to yoursite.com/download_counter. The resulting page is formatted as follows:
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 (http://drupal.org/project/filebrowser).
The filebrowser module allows visitors to easily browse downloadable files on your site.
- Begin by downloading and installing the filebrowser module
- 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.
- Enter a title for the page, and specify the directory you wish to browse, as shown in the following screenshot:
- 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:
- Clicking on a filename will open the file in the browser, and clicking on a directory will open that directory.
- 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.
You may want to only allow authenticated users to view directory listings, in order to provide an additional incentive for registration.
If you have read this article you may be interested to view :
eBook Price: $26.99
Book Price: $44.99
About the Author :
Mark Noble has worked in software development and website design for over 13 years in a variety of capacities including development, quality assurance, and management. He takes pride in developing software and websites to make businesses run more effectively and delights in helping users to get their jobs done more easily.
Mark currently works developing websites to help libraries manage their books. He also does occasional contract work for clients in a variety of industries.
When he isn’t in front of a computer, Mark enjoys playing with his family, photography, and geocaching.