Php WordPress未将文件正确添加到媒体库

Php WordPress未将文件正确添加到媒体库,php,wordpress,Php,Wordpress,我正忙着用WordPress制作我自己的主题。我正在使用处理程序将媒体文件添加到WordPress库。它位于functions.php中,如下所示: function handle_logo_upload() { if ( !function_exists( 'wp_handle_upload' ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } $uploadedfil

我正忙着用WordPress制作我自己的主题。我正在使用处理程序将媒体文件添加到WordPress库。它位于functions.php中,如下所示:

function handle_logo_upload() 
{
    if ( !function_exists( 'wp_handle_upload' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }
        $uploadedfile = $_FILES['file'];
        $upload_overrides = array( 'test_form' => false );
        $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
        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($uploadedfile);
            //wp_die('end');
        }

    return 'fail';      
}
function handle\u logo\u upload()
{
如果(!function_存在('wp_handle_upload')){
require_once(ABSPATH.'wp admin/includes/file.php');
}
$uploadedfile=$_文件['file'];
$upload\u overrides=数组('test\u form'=>false);
$movefile=wp\u handle\u upload($uploadedfile,$upload\u overrides);
如果($movefile){
$wp_filetype=$movefile['type'];
$filename=$movefile['file'];
$wp_upload_dir=wp_upload_dir();
$attachment=array(
'guid'=>$wp\u upload\u dir['url']./'.basename($filename),
'post_mime_type'=>$wp_文件类型,
'post\u title'=>preg\u replace('/\.[^.]+$/','',basename($filename)),
'发布内容'=>'',
“post_状态”=>“继承”
);
$attache\u id=wp\u insert\u attachment($attachment,$filename);
回声“
”; //返回$attach_id; var_dump($uploadedfile); //wp_die(“结束”); } 返回“失败”; }
在这段代码的底部,您可以看到
var\u dump($uploadedfile)这将返回NULL

此外,当我使用主题功能上传图像时,我会在媒体库中得到一个如下所示的文件:


首先想到的是什么?

你可能想在WordPress开发板上发布你的问题,而不是这样。那块板上几乎没有人,这就是为什么我在这里发帖试图得到答案。