0

I have various media file uploads that I need to section off into different subdirectories, for example:

example.com/assets/Uploads

example.com/assets/team

They all go under "/assets" but if I try to change my directory afterward, the media library also switches the location of where it looks for the images.

I have:

define('UPLOADS', '');

Then in my plugin file, the following works, but I can't change it if I want the media library to see my previous uploads:

add_filter('upload_dir', 'set_upload_folder', 999);

function set_upload_folder($uploadData) {

$myDir = '/assets/uploads';

$mainSiteURL = get_site_url();
$uploadData['basedir'] = trailingslashit(ABSPATH) . $myDir;
$uploadData['baseurl'] = $mainSitURL . $myDir;
$subdir = $uploadData['subdir'];
$uploadData['path'] = $uploadData['basedir'] . $subdir;
$uploadData['url'] = $uploadData['baseurl'] . $subdir;

return wp_parse_args($uploadData, $uploadData);

}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.