Great code.
Thanks for providing your plugin!
Ah… I see… hooks + filters in pro version.
Just purchased a copy + will wait for account info. Hopefully this will include information about using hooks + filters.
So if I understand the docs, let me know if this code is correct.
If there’s a better way to do this… say using %user% which in shortcode call, let me know.
Thanks.
_______
if (!function_exists(‘wfu_before_file_upload_handler’)) {
function wfu_before_file_upload_handler($file_path, $file_unique_id) {
$user = wp_get_current_user();
$uid = $user->ID;
$top = ‘user-files’;
$dir = ABSPATH . $top . ‘/’ . $uid;
$path = $dir . ‘/’ . basename($file_path);
return $path;
}
add_filter(‘wfu_before_file_upload’, ‘wfu_before_file_upload_handler’, 10, 2);
}
Hi, your code is correct, however you can also do it much simpler without a hook, by adding the following in the shortcode:
uploadpath = "../user-files/%userid%"
the double-dot takes you to the root folder.
Nickolas
Hey, coming across this thread today.
Was hoping you might be able to help.
I am using this shortcode at the moment:
[wordpress_file_upload uploadpath = “../wp-content/user-uploads/%userid%/” duplicatespolicy = “maintain both” uploadpatterns = “*.pdf, *.doc, *.docx, *.jpg” uniquepattern = “datetimestamp” requiredlabel = “*”]
It’s telling me that “Upload failed! Targer folder doesn’t exist.”
Please help.
Regards
Also – how does the ‘duplicatespolicy’ work?
To my understanding, it should keep both files should one be a duplicate, when the code reads: duplicatespolicy = “maintain both”
Thanks
Hi, first of all you have ../ in upload path, which takes you in root and then wp-content. You can omit all this and just set uploadpath=”user-uploads/%userid%” (because by default uploadpath is relative to wp-content folder).
The error you get means that the folder does not exist. There is an option to automatically create the folder if it does not exist. Just enable it.
duplicatespolicy maintains both files, by renaming the newly uploaded one. By default it will append an increment number in the filename, e.g. file(2).ext, or you can configure it to append the timestamp.
Regards
Nickolas