Wordpress Image Upload Error - Specified file failed upload test
·
Answer a question
I have been trying for hours to get this working.
WP image upload works fine for single image without using multiple tag.
But when tried to to upload multiple images after changing the php code for multiple images (array) and adding multiple tag, show error:
Specified file failed upload test.
File upload data is coming through JSON which works fine when printed.
Below is what I have tried so far:
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 is:
<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>
Please help.
Answers
This can often happen if the $_FILES array is empty. The $_FILES array can be empty for a couple different reasons and more often than not it is because one of the following server settings needs to be changed.
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
更多推荐
所有评论(0)