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.

test
Hi, I am trying to upload a file to http://koditv.uk/kodidl folder.
This is the code [wordpress_file_upload multiple=”false” uploadpath=”http://koditv.uk/kodidl” maxsize=”1000″ showtargetfolder=”true” subfoldertree=”auto”]
Cant get it to work.
Do you have any sugestions?
I still dont get any output to the screen if I use this method and add an echo at the end of the snippet.
I am trying to use the hook that checks if the upload was successful so that my own plugin can go ahead and parse the uploaded file but this doesnt seem to work at all.
im lost please help.
Thanks Chris