I am trying to add an async upload to my Drupal 6 custom module. The problem is, though, that when the upload occurs (I have a break point on my php function) no data can be seen in $_POST or $_FILES. All the data for the file gets put into $HTTP_RAW_POST_DATA. I would expect it to be in the $_FILES array. Can anyone tell me what I'm doing wrong. Or at least how to use $HTTP_RAW_POST_DATA to process the file on the backend. Here is my code:
On my_module_viewer.views.inc
<form id='my_upload_form' enctype='multipart/form-data' method='POST'>
<input type='file' name= 'file_upload' id= 'file_upload' multiple>
<input type='button' name ='file_upload_button' id ='file_upload_button' value= 'Upload' />
</form>
Java Script:
$('#file_upload_button').click(function(){
var files = $( '#file_upload' )[0];
var data = new FormData();
jQuery.each(files.files, function(i, file) {
data.append('file-'+i, file);
});
var request_timeout = 50000;
var url = Drupal.settings.basePath + 'my_module/cases/add_attachment';
$.ajax({
url: url,
data:data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
beforeSend: function(xhr ){
$.blockUI({
message: "Uploading File. Please Wait.",
css: {
border: 'none',
padding: '15px',
backgroundColor: '#333',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .9,
color: '#fff',
fontSize: '26px',
fontFamily: "'Helvetica Neue', Helvetica"
}
});
},success: function(data) {
$.unblockUI();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$.unblockUI();
}
});
});
As I mentioned, this is being written in Drupal 6. I'm not sure if this is relevant, but here is my menu for that task:
Found on my_module.module
$items['my_module/cases/add_attachment']= array(
'page callback' => 'add_attachment',
'access arguments' => array('add attachment for user'),
'type' => MENU_CALLBACK,
'access callback' => true,
'file' => 'my_module_viewer.views.inc'
);