最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

errors - media_handle_upload() returns Specified file failed upload test

programmeradmin0浏览0评论

I am trying to make media_handle_upload() work but I keep getting 'Specified file failed upload test.' This is how I am testing it:

<html>
<body>
    <form method="post" enctype='multipart/form-data'>
    <input type="file" id="file_to_upload" name="dlkimage1" />
<?php
    require($_SERVER['DOCUMENT_ROOT'].'/wp/wp-load.php');
    require_once( ABSPATH.'wp-admin/includes/file.php' );

    if ( isset($_FILES["dlkimage1"]) && !empty($_FILES["dlkimage1"]["tmp_name"]) )
        $image_id = media_handle_upload(
                            $_FILES["dlkimage1"]["tmp_name"],   // file
                            0,                                  // ID of image post
                            array(),                            // post data (to overwrite some of the attachment)
                            array('test_form' => false) );
    if ( is_wp_error($image_id) )
        echo 'ERROR: ' . $image_id->get_error_message();
    else
        echo $image_id;
?>
    <button class="button" id="updatepreview" type="submit" />Update Preview</button>
    </form>
</body>
</html>

What am I missing?

发布评论

评论列表(0)

  1. 暂无评论