Drupal7: Filefield Sources Module

David G - Drupal

In my Drupal usage and experience I have come to use many modules. But often I find myself learning new features about a module I’ve been previously using. When this happens I try to evaluate how this makes the module more flexible, or limiting if I encountered a bug I didn’t expect. A module I use often is Filefield Sources — but until recently I did not know it could easily move files around your file-system (within reason).

I have a website that allows students to submit images via a Webform for staff to collect and use elsewhere in digital and print media. Staff should be able to get the uploaded files from an FTP directory setup for the client. Recently I was told:

  1. The uploaded images did not have the correct filenames format, nor were they found within the expected FTP directory (oops).
  2. In a Drupal meeting today a co-worker said sometimes he wishes he could move a Fields upload directory someplace other than sites/default/files (eg, out of a big catch all file uploads directory).

FileField Sources module can fix both of these issues! WITH 0 CODE CHANGES! Wooo!

Filefield Sources basically extends the basic File type with additional file location options (for starters). So per file you can provide a destination location directory for the file field, if you have Tokens enabled on your site you can use any of the Nodes tokens to create the filename. This solves issue (1) above.

Filefield Sources also provides a mechanism (which should be tried outside of your production site first!) to retroactively change existing saved file fields to new destination locations based on the destination rule. It uses the Batch API on the backend to support hundreds (or thousands) of files! This solves issue (2) above.

An example of this field configuration is:

Filefield Sources configuration for a Node's uploaded file.

Filefield Sources configuration for a Node’s uploaded file.

Note: One option I’m aware of and is a best-practice, but have yet to actually use on my sites is the Transliteration module which Filefield Sources may use if installed. This option would change bad filenames like “Mary ~~ 11.jpg” to say “mary__11.jpg” for example. Also this module has Drush integration so moving files and setting file path rules can be done via the command line even … sweet!

I hope you find these interesting features of the Filefield Sources module really helpful — I know I did!

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *