Wordpress上传文件夹子目录

时间:2017-05-12 23:53:25

标签: php wordpress upload directory

我在Wordpress uploads文件夹中创建了许多子文件夹,并希望根据仪表板中显示的当前页面以编程方式指定文件应上传到哪个文件夹。

这是我到目前为止的代码:

function field_name_upload_prefilter($errors) {
    // in this filter we add a WP filter that alters the upload path
    add_filter('upload_dir', 'field_name_upload_dir');
        return $errors;
}
// Second filter
function field_name_upload_dir($uploads) {
    // here is where we later the path
    if($pagenow == 'archive'){
        $uploads['path'] = $uploads['basedir'].'/archive';
        $uploads['url'] = $uploads['baseurl'].'/archive';
        $uploads['subdir'] = '';
    }

    if ($pagenow = 'assets') {
        $uploads['path'] = $uploads['basedir'].'/assets';
        $uploads['url'] = $uploads['baseurl'].'/assets';
        $uploads['subdir'] = '';
    }

    return $uploads;
}

0 个答案:

没有答案