Answers:
在Justice Is Cheap的领导下,我结束了对该插件的功能调整:http : //wordpress.org/extend/plugins/custom-upload-dir/
<?php
/*
* Change upload directory for PDF files
* Only works in WordPress 3.3+
*/
add_filter('wp_handle_upload_prefilter', 'wpse47415_pre_upload');
add_filter('wp_handle_upload', 'wpse47415_post_upload');
function wpse47415_pre_upload($file){
add_filter('upload_dir', 'wpse47415_custom_upload_dir');
return $file;
}
function wpse47415_post_upload($fileinfo){
remove_filter('upload_dir', 'wpse47415_custom_upload_dir');
return $fileinfo;
}
function wpse47415_custom_upload_dir($path){
$extension = substr(strrchr($_POST['name'],'.'),1);
if(!empty($path['error']) || $extension != 'pdf') { return $path; } //error or other filetype; do nothing.
$customdir = '/pdf';
$path['path'] = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
$path['url'] = str_replace($path['subdir'], '', $path['url']);
$path['subdir'] = $customdir;
$path['path'] .= $customdir;
$path['url'] .= $customdir;
return $path;
}
您可以在wordpress中从wp-config.php文件更改上传目录。
define('UPLOADS','myimages'); 确保在以下行之前添加此代码:
require_once(ABSPATH.'wp-settings.php');
这允许您将媒体上传到myimages文件夹中,而不是wp-content / uploads
谢谢
pdf
仅更改文件的上载文件夹。