Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress上载文件夹子目录_Php_Wordpress_Upload_Directory - Fatal编程技术网

Php Wordpress上载文件夹子目录

Php Wordpress上载文件夹子目录,php,wordpress,upload,directory,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_di

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

正常检查,研究那边的钩子名称可以提供很多解决方案。你的新文件夹名称是什么样子的?。它是否与页面slug名称相同?