18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Working with Files and Images<br />

We will also be creating a second module, which allows users to add a simple<br />

text watermark to images. Users will be able to configure the watermark so that<br />

it displays custom text in a specified color. This effect will be available for use in<br />

Image Styles, the <strong>Drupal</strong> 7 implementation of the Imagecache module.<br />

Files in <strong>Drupal</strong><br />

When you installed <strong>Drupal</strong> for the first time, you probably got the following error<br />

and wondered why you needed to create three directories for files:<br />

<strong>Drupal</strong> defines three types of file storage, namely, public, private, and temporary.<br />

Public files are available to the world at large for viewing or downloading. This is<br />

where things such as image content, logos, and downloadable files are stored. Your<br />

public file directory must exist somewhere under <strong>Drupal</strong>'s root, and it must be<br />

readable and writeable by whatever 'user' your web server is running under. Public<br />

files have no access restrictions. Anyone, at anytime, can navigate directly to a public<br />

file and view or download it.<br />

Private files are not available to the world for general download. The private files'<br />

directory should reside outside <strong>Drupal</strong>'s root directory. However, it will still be<br />

writeable by the web server user. Isolating private files this way allows developers<br />

to control who can and can't access them as they wish. For instance, you could write<br />

a module that only allows users who have a specific role, to access PDFs in the<br />

private filesystem.<br />

[ 314 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!