Renaming files
In the last recipe we changed the upload folder to images/stories/chronoforms
but we are still getting the default image names — in this case 20100126161249_test_image.jpg
. In this recipe, we'll look at ways to change the file names to more useful values for your application.
Getting ready
We'll continue with the same form as in the previous recipe.
How to do it...
1. Go back to the Form Editor and click the File Uploads tab.
In the FileName Format box you'll see an entry like this:
$filename = date('YmdHis').'_'.$chronofile['name'];
This is a PHP snippet that sets the value of the
$filename
variable that ChronoForms will use to rename the uploaded file.There are two main pieces to it, joined by an underscore '_':
The first piece is
date('YmdHis')
. This is a PHP command to get the current date and time in the format set by'YmdHis'
.The second piece is
$chronofile['name']
which is the temporary variable that holds the original name of the uploaded file.Lastly there's a semi-colon...