---Solved
By replacing
$.ajax({ // create an AJAX call...
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
processData: false,
cache: false,
contentType: false,
data: formData, // get the form data
beforeSend: function() {
$(".dynamicContentWindow").load("loading.php"); // hides the window during load
},
success: function(data, status) { // on success..
$(".dynamicContentWindow").html(data); // update the DIV
contentLoaded(); //recall the catchers for the new page
},
});
with:
var request = new XMLHttpRequest();
request.open("POST", $(this).attr('action'));
request.send(formData);
solves the problem. However, I do not understand why and I think it is neither explained in another post. If somone would be able to point that out it would be a great relieve.
Heyho everyone, I am quite new to working with jQuery and I am currently trying to establish an asynchronous file upload with ajax. However my requests ends all the time up in the php://input and is not passed to $_POST or $_FILES. I googled the complete day yesterday and tried several things, but I am not able to figure out the problem. The server used is apache 2.2.9 (yes it is actually ready for the museum, but it was not my choice)
The html code is in this case:
<form action="ua_import_files.php" method="POST" enctype="multipart/form-data" class="file">
<input type="hidden" name="tab_select" value="0" />
<input type="hidden" name="MAX_FILE_SIZE" value="9999000000" />
<input type="hidden" name="file_type" value="planview" />
<input name="uploadedfile" type="file" size="40" style="background:#D0D0D0; font-size:10px; margin-top:7px;" /></p>
<br/>
<br/>
<input type="submit" value="Upload File" style="font-size:12px; width: 100px; margin-top:7px; float:left;display:block;" />
</form>
the related javascript code is:
$("form").each(function() {
if($(this).attr('class') == "file") {
$(this).submit(function(e){
e.preventDefault(); // cancel original event to prevent form submitting
console.log("File Upload, FileReader: " + window.FileReader + "FormData: " + window.FormData);
var form = new FormData(this);
console.log(form);
$.ajax({ // create an AJAX call...
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
beforeSend: function() {
$(".dynamicContentWindow").load("loading.php"); // hides the window during load
},
success: function(data, status) { // on success..
$(".dynamicContentWindow").html(data); // update the DIV
contentLoaded(); //recall the catchers for the new page
},
data: form, // get the form data
processData: false,
contentType: false,
cache: false
});
});
}
});
Hereby the console.log() produces an output as well. But if I then dump $_FILES or $_POST on the server I get in both cases empty arrays. However, when dumping file_get_contents("php://input") i get this:
string(2941129) "-----------------------------29431251527956 Content-Disposition: form-data; name="tab_select" 0 -----------------------------29431251527956 Content-Disposition: form-data; name="MAX_FILE_SIZE" 9999000000 -----------------------------29431251527956 Content-Disposition: form-data; name="file_type" exp -----------------------------29431251527956 Content-Disposition: form-data; name="uploadedfile"; filename="file.exp" Content-Type: application/octet-stream EXP op 2015-08-13T00:00:00.000Z 2016-01-01T00:00:00.000Z XXX XXX ..."
(I only but some of the string in here) I already checked the config files, which should give enough resources to the server to process the request:
memory_limit = 128M;
max_execution_time = 3600;
max_input_time = 600;
upload_max_filesize = 30M
post_max_size = 100M
I assume, that I have either something wrong with the headers, which stops the server of parsing the data or another mistake in the config,w hich I did not found yet. Does anyone has an idea?