更改PDF文件的上传目录


Answers:


17

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;
}

您好...需要上传到“ / wp-content / uploads /”文件夹之外。请帮忙
Ivan Slaughter

1

您可以在wordpress中从wp-config.php文件更改上传目录。

define('UPLOADS','myimages'); 确保在以下行之前添加此代码:

require_once(ABSPATH.'wp-settings.php');

这允许您将媒体上传到myimages文件夹中,而不是wp-content / uploads

谢谢


这不能回答问题。最初的问题是pdf仅更改文件的上载文件夹。
Sinklar '17
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.