html:
<input id="fileSelect" type="file" name="files[]" multiple="multiple" accept="image/*" />
js:
alert( filesArray );
3 three images.//
// [object File],[object File],[object File]
// new FormData object.
var formData = new FormData();
formData.append( 'files[]', filesArray );
jQuery.ajax
({
url: ajaxurl, // uploadfile.php
type: "POST",
data: {
action: 'auto_post',
form_data: formData
},
processData: false,
contentType: false,
success: function( data )
{
alert( data );
},
error: function( data )
{ }
});
When i don't use:
processData: false,
contentType: false,
I got: (error)
TypeError: 'append' called on an object that does not implement interface FormData.
What to do now? I need the the formData to send to the php server side using ajax.
uploadfile.php
I need to access like this here:
$_FILES["files"]["name"];
Ajax data get here:
// Ajax Funtion.
function aap_auto_post()
{
echo $_FILES['files']['name'];
die();
}
add_action( 'wp_ajax_auto_post', 'aap_auto_post' );
add_action( 'wp_ajax_nopriv_auto_post', 'aap_auto_post' );