Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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自定义文件错误:上载图像返回$\u文件为空_Php_Wordpress - Fatal编程技术网

Php Wordpress自定义文件错误:上载图像返回$\u文件为空

Php Wordpress自定义文件错误:上载图像返回$\u文件为空,php,wordpress,Php,Wordpress,这是关于wordpress主题开发的 我在类别创建和编辑表单中添加了两个自定义字段(文本和上传图像)所有功能在编辑表单中都能正常工作在创建表单$\u POST中运行良好,但$\u文件为空。 我正在本地Windows上使用Wamp进行测试,因此有足够的空间 php.ini ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-up

这是关于wordpress主题开发的

我在类别创建和编辑表单中添加了两个自定义字段(文本和上传图像)所有功能在编辑表单中都能正常工作在创建表单$\u POST中运行良好,但$\u文件为空。

我正在本地Windows上使用Wamp进行测试,因此有足够的空间

php.ini

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "D:/Program Files/wamp/tmp"

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 64M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

post_max_size = 64M
functions.php

/*=====================================
=            category form            =
=====================================*/

// add file upload permission to category edit form
add_action ( 'category_edit_form', 'edit_form_tag');
function edit_form_tag() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery('#edittag').attr( "enctype", "multipart/form-data" );
        });
    </script>
    <?php 
}

add_action ( 'category_add_form', 'create_form_tag');
function create_form_tag() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery('#addtag').attr( "enctype", "multipart/form-data" );
        });
    </script>
    <?php 
}


//add extra fields to category create form hook
add_action ( 'category_add_form_fields', 'create_extra_category_fields');
//add extra fields to category create form callback function
function create_extra_category_fields( $tag ) {    //check for existing featured ID
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_{$t_id}");
    ?>
    <div class="form-field">
        <label for="cat_style_type"><?php _e('Category Style Type'); ?></label>
        <select name="Cat_meta[cat_style_type]" id="cat_style_type" >
            <option value="text" <?php echo ($cat_meta['cat_style_type'] == 'text') ? 'selected' : ''; ?>><?php _e('text'); ?></option>
            <option value="news" <?php echo ($cat_meta['cat_style_type'] == 'news') ? 'selected' : ''; ?>><?php _e('news'); ?></option>
        </select>
        <p class="description"><?php _e('Required. Category style type: text or news.'); ?></p>
    </div>
    <div class="form-field">
        <label for="cat_Image_url"><?php _e('Category Image Url'); ?></label>
        <input type="file" name="cat_img" id="cat_Image_url" ><br />
        <p class="description"><?php _e('Image for category. If category\'s style is text, it\' optional; if category\'s style is news, it\'s required.'); ?></p>
        <img src="<?php echo $cat_meta['cat_img'] ? $cat_meta['cat_img'] : ''; ?>" style="max-width: 300px;height: auto;margin-top: 10px;">
    </div>
    <?php
}

//add extra fields to category edit form hook
add_action ( 'category_edit_form_fields', 'edit_extra_category_fields');
//add extra fields to category edit form callback function
function edit_extra_category_fields( $tag ) {    //check for existing featured ID
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_{$t_id}");
    ?>
    <tr class="form-field">
        <th scope="row" valign="top"><label for="cat_style_type"><?php _e('Category Style Type'); ?></label></th>
        <td>
            <select name="Cat_meta[cat_style_type]" id="cat_style_type" >
                <option value="text" <?php echo ($cat_meta['cat_style_type'] == 'text') ? 'selected' : ''; ?>><?php _e('text'); ?></option>
                <option value="news" <?php echo ($cat_meta['cat_style_type'] == 'news') ? 'selected' : ''; ?>><?php _e('news'); ?></option>
            </select>
            <p class="description"><?php _e('Required. Category style type: text or news.'); ?></p>
        </td>
    </tr>
    <tr class="form-field">
        <th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
        <td>
            <input type="file" name="cat_img" id="cat_Image_url" ><br />
            <p class="description"><?php _e('Image for category. If category\'s style is text, it\' optional; if category\'s style is news, it\'s required.'); ?></p>
            <img src="<?php echo $cat_meta['cat_img'] ? $cat_meta['cat_img'] : ''; ?>" style="max-width: 300px;height: auto;margin-top: 10px;">
        </td>
    </tr>
    <?php
}

// save extra category extra fields hook
add_action ( 'create_category', 'save_extra_category_fileds');
add_action ( 'edited_category', 'save_extra_category_fileds');
// save extra category extra fields callback function
function save_extra_category_fileds( $term_id ) {
    if ( isset( $_POST['Cat_meta'] ) ) {
        $t_id = $term_id;
        $cat_meta = get_option( "category_{$t_id}");

        $cat_meta['cat_style_type'] = $_POST['Cat_meta']['cat_style_type'];

        if ( ! function_exists( 'wp_handle_upload' ) ) {
            require_once( ABSPATH . 'wp-admin/includes/file.php' );
        }

        $uploadedfile = $_FILES['cat_img'];

        $movefile = wp_handle_upload( $uploadedfile, array( 'test_form' => false ) );

        if ( $movefile && ! isset( $movefile['error'] ) ) {
            $cat_meta['cat_img'] = $movefile['url'];
        } else {
            echo $movefile['error'];
        }

        // save the option array
        update_option( "category_{$t_id}", $cat_meta );
    }
}

/*=====  End of category form  ======*/
/*=====================================
=类别表格=
=====================================*/
//将文件上载权限添加到类别编辑表单
添加动作('category_edit_form'、'edit_form_tag');
函数编辑\表单\标签(){
?>
jQuery(文档).ready(函数(){
jQuery('#edittag').attr(“enctype”,“多部分/表单数据”);
});
jQuery(文档).ready(函数(){
jQuery('#addtag').attr(“enctype”,“多部分/表单数据”);
});


“style=”最大宽度:300px;高度:自动;页边距顶部:10px;”>


“style=”最大宽度:300px;高度:自动;页边距顶部:10px;”>
$\u FILES['CatMetaImg']
正在使用输入id。这不应该是输入名称吗?

$\u FILES['CatMetaImg']
正在使用输入id。这不应该是输入名称吗?

我现在修复了这个错误,仍然不起作用。我可以以编辑形式上载,但不能以创建形式工作。我正在使用print\r($\u文件)以前,它返回空的,所以事实上它与$\u文件['CatMetaImg']无关,尽管它是错误的。我现在修复了这个错误,仍然不起作用。我可以在编辑表单中上载,但在创建表单中不起作用。我以前使用过print\r($\u文件),它返回空的,所以事实上它与$\u文件['CatMetaImg']无关,尽管它是错误的。