Many users ask whether the upload path of the Iptanus File Upload plugin can be customised. It can, and this article shows how.
What this example does
In the example below, uploaded files are added to the site’s Media library (the medialink attribute is set to “true”). When medialink is true the plugin ignores the path in the uploadpath attribute and uses the default WordPress upload folder. We will keep files inside that folder, but send them to subdirectories named after the user who uploaded them.
The steps
To do that we need Code Snippets, a third-party plugin that lets us hook into the filters and actions of Iptanus File Upload and set specific options. Here are the steps:
1. Install Code Snippets.
2. Go to Snippets in your Dashboard and create a new snippet.
3. Give it any name you like, and paste the following code into the Code box:
if (!function_exists('wfu_before_file_upload_handler')) {
function wfu_before_file_upload_handler($file_path, $file_unique_id) {
//get the current user
$user = wp_get_current_user();
if ( $user->ID != 0 ) {
//extract filename from $file_path
$filename = wfu_basename($file_path);
//get upload dir structure
$upload_dir = wp_upload_dir();
//construct new upload dir from upload base dir and the username of the current user
$new_file_dir = $upload_dir['basedir'].'/'.$user->user_login;
//create the new file dir, if it is does not exist
if ( !is_dir($new_file_dir) ) mkdir($new_file_dir, 0777, true);
//return the new file path
return $new_file_dir.'/'.$filename;
}
}
add_filter('wfu_before_file_upload', 'wfu_before_file_upload_handler', 10, 2);
}
4. Leave the other options as they are and press “Save Changes and Activate”.
5. In the plugin’s Shortcode Composer, go to the Interoperability tab and enable “Add Uploaded Files To Media”. You can also just add medialink=”true” to the shortcode instead.
6. That is all. When a logged-in user uploads a file, it is added to the site’s Media library, at the path “/wp-content/uploads/%username%”, where %username% is that user’s username.
Adapting it
This is a small example of what the plugin’s filters and actions can do. The code can be adapted to build upload directories of your own, and it can rename the uploaded file too.
Note that this code runs after all of the plugin’s own checks. If the upload directory or the filename it returns is invalid, the plugin cannot detect it — the upload is simply rejected without a specific error. Add your own checks inside the code to make sure the path is valid.
If you have questions or need assistance, please contact the Iptanus team.

How would I create a directory based on user input – like if I had a Name field as part of the upload, how do I create a directory named after that name (as opposed to the wp user ID)?
Also (and I suspect this one is trickier): is there a way to assign a new directory if you’re using Dropbox uploads?
Hi, if you set uploadpath=”/uploads/%userdata1%” then %userdata1% variable will be replaced by the value entered by the user in the first field. If you use %userdata2% the second and so on.
Regarding Dropbox folders, if the folder does not exist then it will be created automatically.
Regards
Nickolas
file uploaded but my file location on /uploads/year/month/
how to fix it?
My Shortcode
[wordpress_file_upload uploadpath=”uploads/%userdata2%/%userdata3%/%userdata1%/%userdata4%/”]
Do you have the Free or Pro version?
Regards
Nickolas
This worked like a charm! Thank you! So glad I got the Pro version too.
Great working fine and easy 🙂
for the Snippets you can Also use Woody snippets