'上传测试失败'在WordPress中上传文件时

时间:2015-09-11 14:18:30

标签: php wordpress file-upload

所以我在WordPress中忙于制作自己的主题并忙于设置页面:

我准备将文件保存到媒体库的处理程序。这是处理程序代码:

function handle_logo_upload() {
    if ( !function_exists( 'wp_handle_upload' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }
        $upload_overrides = array( 'test_form' => false );
        $uploadedfile = $_FILES['upload_logo']['name'];
        $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
        print_r($movefile);
        wp_die();
        if ( $movefile ) {
            $wp_filetype = $movefile['type'];
            $filename = $movefile['file'];
            $wp_upload_dir = wp_upload_dir();
            $attachment = array(
                'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
                'post_mime_type' => $wp_filetype,
                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
                'post_content' => '',
                'post_status' => 'inherit'
            );
            $attach_id = wp_insert_attachment( $attachment, $filename);
            echo '<br>';
            //return $attach_id;
            //var_dump($movefile);
            print_r($movefile);
            //wp_die('end');
        } else {
            return 'fail';      
        }
}

正在抓取文件名,但当我在print_r上执行$movefile时,出现以下错误:Array ( [error] => Specified file failed upload test. )

没有文件添加到媒体库。

我需要对我的代码做什么才能通过测试?

以下是我的主题设置页面的屏幕截图:http://pasteboard.co/yFck7LW.png

0 个答案:

没有答案