File Upload Field
Uploaded Filenames
With version 2.2.0 of this module you can now customize the filenames that are created when a user uploads a file. To customize the filename, you'll need to edit the Filename format setting in the Edit field dialog, found in the Edit Form » Fields page.
Placeholders
These are special placeholders that can be used in your Filename format field to control how the filename is generated. See below for some examples on how they can be used.
{$clean_filename}
$g_filename_char_whitelist
setting in your
config.php file for more info. Those
whitelisted characters are what's used to determine the clean filename.
{$clean_filename_no_extension}
{$raw_filename}
{$raw_filename_no_extension}
{$extension}
{$form_id}
{$submission_id}
{$index}
{$field_name}
{$date}
{$unixtime}
date_format
modifier like so:
{$unixtime|date_format:"M-n-Y"}
. The content of the double quotes are whatever formatting string
you'd like. See the PHP date method for the list of
available placeholders.
Note that in case of a filename conflict, the module will rename files to ensure each filename is unique. So if you upload a file that happens to have the same name as an existing file - even after whatever custom filename format you entered, it will still automatically rename it.
Examples
Here are a few examples to get an idea of how you can use the placeholders in the field. As you can see from below, any characters that aren't in a placeholder get included in the filename. The one exception is the colon character: that's not a valid character in filenames on Unix or Windows systems so it will always be stripped out, even if it's part of your date formatting string.
{$submission_id}-{$field_name}-{$index}.{$extension}
- 35-filefield-0.png
- 35-filefield-1.png
- 35-filefield-2.png
{$submission_id}-{$field_name}-{$index+1}.{$extension}
- 35-filefield-1.png
- 35-filefield-2.png
- 35-filefield-3.png
f{$form_id}-s{$submission_id}-{$clean_filename}
- f5-s39-infodoc.xls
- f5-s29-happypic.jpg
{$clean_filename_no_extension}-{$date}.{$extension}
- greenbug-20190127.png
- fritillarybutterfly-20190127.gif
{$clean_filename_no_extension}-{$date}.{$extension}
- greenbug-20190127.png
- fritillarybutterfly-20190127.gif
{$clean_filename_no_extension}-{$unixtime|date_format:"MjS-h-ia"}.{$extension}
- aniseswallowtail-Jan27th-05-48pm.png
- beetle-Jan27th-05-48pm.png