I created a frontend form using a plugin which allows logged in users to create draft posts. There are 3 file upload areas. I need 1 of them to use the default public WP media upload folder as usual. But I need the files uploaded via 2nd and 3rd file upload areas to move to a restricted sub folder inside the default WordPress file upload folder. 1 of them allow multiple file uploads.
Important facts:
- I have changed the default
WP_CONTENT
folder andUPLOADS
folder usingwp-config.php
- One of the file upload areas allows multiple file uploads
This is the file upload field generated by a custom plugin:
<input type="text" class="multiple_files" data-formid="11" data-fieldname="multiple_files" placeholder="http://" name="files[0]" value="" data-required="yes" data-type="multiple" required="" autocomplete="off">
People can choose to add more, then the name changes to files[1], files[2]
, so on..
What I basically need is something like this:
add_filter('wp_handle_upload_prefilter', 'custom_upload_prefilter');
add_filter('wp_handle_upload', 'custom_upload_handle');
function custom_upload_prefilter($file){
add_filter('upload_dir', 'custom_upload_dir');
return $file;
}
function custom_upload_handle($fileinfo){
remove_filter('upload_dir', 'custom_upload_dir');
return $fileinfo;
}
function custom_upload_dir($path){
if ( isset( $_REQUEST['files'][0] ) ) {
$customdir = '/secured'. $path['subdir'];
$path['path'] = $path['basedir'] . $customdir;
$path['url'] = $path['baseurl'] . $customdir;
}
return $path;
}
But $_REQUEST
only works when you have submitted the form, not when you upload the files.
I'm new to WordPress. I looked around to find an exact solution to my issue. there are a few solution but I not exactly what I'm looking for. Thank you very much.
attachment
, WordPress itself doesn't care about the location of the files, and there's no built in capability to restrict access to those folders as they're served directly by Apache/Nginx, so to talk about multiple locations doesn't make much sense. Since this isn't a discussion forum, and people need to be able to write a specific answer that fully answers your question, what kind of answer are you looking for? I notice there is no code in your question to work with, can you edit your Q to include it? What problem does this solve?$_REQUEST
doesn't contain the file data, then try with$_FILES
, but as @Olivier said, you need to know the code (JS/PHP) used for uploading the file / processing it on the server. But are you sure$_REQUEST
doesn't actually contain any data specific to the uploaded file (or upload form) - tryvar_dump( $_REQUEST, $_FILES )
?