admin管理员组

文章数量:1122846

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

example/assets/Uploads

example/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);

}

本文标签: phpChanging upload directory temporarily