When the files are uploaded we would like to put them into their own user folder under the upload folder.
The "Upload Files" action has a parameter to set the upload path for files, but this is a static parameter, and so it can't be changed based on the logged in user's data or any other dynamic data, the only way to change this in the run time is through a "Custom Code" action.
Please drag a "Custom Code" action BEFORE the "Upload Files" action and insert the code below:
v5:
<?php $user = JFactory::getUser(); $form->actions_config[77]["upload_path"] = "FULL_PATH_TO_FILE".DS.$user->get('username').DS; ?>v4:
<?php
$user = JFactory::getUser();
$form->set("upload_files_77", "upload_path", "JOOMLA_PATH".DS."components".DS."com_chronoforms".DS."uploads".DS.$user->get('username').DS);
?>
The code above will change the "upload_path" parameter in the "Upload Files" action with ID = 77 to the new path dynamically generated based on the logged in user's username.
Some important notes:
- Please remember that the action id number is written in red/v4 or blue/v5 beside the action name in the form wizard.
- The parameters names can be found in the source .php files of the actions.
- The path is dependent on your server, find the correct absolute path on your server, but the one above should work fine since the "JOOMLA_PATH" string will be replaced by the absolute path to your Joomla root.
- It's better that you make sure your form is only accessible by logged in users in this situation.
- The same solution above can be used to change any action's parameter dynamically, as long as you change the action id and parameter name accordingly.
Comments: