所以我想更改我的上传目录。我可以通过以下方式进行更改:
add_filter( \'pre_option_upload_url_path\', \'wpse_77960_upload_url\' );
function wpse_77960_upload_url() {
return \'http://subdomain.example.com/files\';
}
或
update_option(\'upload_url_path\', \'/wp-content/uploads\');
source或者类似于:
register_setting( \'media\', \'upload_url_path\', \'esc_url\' );
当涉及到整体速度时,有没有更好的方法?我试过使用
define( \'UPLOADS\', \'http://absolute/path/to/dir\' );
, 但它一直在所有上传的网站url前加上前缀。
SO网友:gmazzap
您可以使用\'upload_dir\'
滤器
add_filter(\'upload_dir\', \'set_upload_folder\', 999);
function set_upload_folder( $upload_data ) {
// absolute dir path, must be writable by wordpress
$upload_data[\'basedir\'] = trailingslashit(ABSPATH). \'/files\';
$upload_data[\'baseurl\'] = \'http://subdomain.wptest.com/files\';
$subdir = $upload_data[\'subdir\'];
$upload_data[\'path\'] = $upload_data[\'basedir\'] . $subdir;
$upload_data[\'url\'] = $upload_data[\'baseurl\'] . $subdir;
return wp_parse_args($upload_data, $upload_data);
}
无论“年/月子文件夹”选项处于打开或关闭状态,此代码都将起作用。
请注意,当然,您需要配置DNS以将新url指向正确的文件夹。