Wordpress图片上传错误-指定的文件上传测试失败

问题描述 投票:2回答:1

我已经尝试了几个小时才能使它正常工作。

WP图像上传在不使用multiple标签的情况下,对单个图像效果很好。

但是在更改多个图像(数组)的php代码并添加multiple标签后尝试上传多个图像时,显示错误:

指定的文件上传测试失败。

文件上传数据通过JSON发送,在打印时效果很好。

下面是我到目前为止尝试过的内容:

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

    foreach($styledNameData as $nameData){
        //echo '<pre>'; print_r($nameData);
        // It Prints
        //Array
        //(
        //  [name] => A_Front.png
        //  [type] => image/png
        //  [tmp_name] => C:\\xampp\\tmp\\php5BFB.tmp
        //  [error] => 0
        //  [size] => 32901
        //)

        $upload_overrides = array('test_form' => false);
        $movefile = wp_handle_upload($nameData, $upload_overrides);
    }
    if($movefile && !isset($movefile['error'])){
        echo '<pre>';
        print_r($movefile);
    } else {
        echo '<pre>';
        print_r($movefile['error']);
    }

HTML是:

<form id="imagesForm" method="POST" enctype="multipart/form-data" action="<?php echo admin_url('admin-ajax.php'); ?>">
    <input id="uploadfile" type="file" class="button button-secondary" name="uploadfile[]" multiple />
    <input type="hidden" name="action" value="shpg_image_upload" />
    <input type="submit" id="uploadImages" name="uploadImages" class="btn-medium col-sms-5 col-sm-3" value="UPLOAD" />
</form>

请帮助。

wordpress image image-uploading
1个回答
0
投票

如果$ _FILES数组为空,通常会发生这种情况。 $ _FILES数组可能为空,这有几个不同的原因,并且经常是因为需要更改以下服务器设置之一。

file_uploads=Off <--- Set this to On

post_max_size=8M <-- increase this to be larger than your image

upload_max_filesize=2M <-- increase this to be larger than your image
© www.soinside.com 2019 - 2024. All rights reserved.