So, i’m trying to find out a way to use two separate upload folders, being the default one wp-content/uploads
for general media uploads, and another one say wp-content/custom
for one specific type of attachments (PDF files attached to one specific post_type).
It is important to keep’em separated both for organization and data security as the PDF files will hold somewhat sensitive data that should only be acessible by two custom user roles, while general media is, well, general.
I’m a little embarrassed to show you the code i got working, because it’s lousy, but here it goes:
function custom_post_type_metabox_save_function($post_id) {
global $post;
// Verify auto-save, nonces, permissions and so on then:
update_post_meta($post_id, "meta_key1", $_POST["value1"]);
update_post_meta($post_id, "meta_key2", $_POST["value2"]);
// this is where it gets uply. I change the 'upload_path' to my desired one for this post type
update_option('upload_path','wp-content/custom-upload-dir');
// then upload the file to it
wp_upload_bits($_FILES["pdfexame"]["name"], null, file_get_contents($_FILES["pdfexame"]["tmp_name"]));
// and then change it back to default... :$
update_option('upload_path','');
}
add_action('save_post','custom_post_type_metabox_save_function');
I’d really rather just have 2 upload files being one for this post-format and another for the rest. Is there a cleaner way to go about it?
I ended up solving it by completely bypassing the wp upload system, so this is how it looks now:
It’s well less ugly than what i had before, but still would be much better if this could be done using the
upload_dir
filter.