Good day guys. I’ve been uploading files (docs and images) from AJAX. Although, I’ve searched this site for uploading videos from AJAX, I have not seen exactly what I want. I only saw, uploading a live-stream video and that does not really help me.
Now, I want to upload all three (docs, audio and video) from AJAX. The code below works well when I select only .DOC to upload but it does not work when I combine .DOC and .MP4 files.
var fdata = new FormData(); fdata.append("cid", $("#tclass").val() ); fdata.append("subj", $("#tsubj").val() ); fdata.append("sess", $("#sess").val() ); fdata.append("term", $("#term").val() ); fdata.append("title", $("#lessontitle").val() ); if( $("#lessontext").val() !== ""){ fdata.append("note", $("#lessontext").val() ); } fdata.append("video", $("#videofile")[0].files[0] ); fdata.append("doc", $("#docfile")[0].files[0] ); fdata.append("audio", $("#audiofile")[0].files[0] ); document.getElementById("msgStatus").innerHTML = "Uploading Lesson and Checking for Previously Uploaded Title"; $.ajax({ type: 'POST', url: "lessons/validateupload/", data:fdata, contentType: false, processData: false, cache: false, success: function(data){ alert(data); $('#msgStatus').html(data); if(data.indexOf("successfully") > -1){ closeForm(); } } })
THE RESULT RETURNED FROM PHP WHEN I SELECT ONLY .doc
Array ( [cid] => 1-JSS1A [subj] => 1-MATHEMATICS [sess] => 1 [term] => 1 [title] => INTEGRATION [note] => thhis is a mathematical concept... => undefined => undefined ) Array ( [doc] => Array ( [name] => Design and Implementation of a Web.docx [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [tmp_name] => C:wamp64tmpphp9185.tmp [error] => 0 [size] => 711124 ) )
AND THIS IS THE RESULT WHEN I COMBINE .doc FILE AND .mp4 FILE I get empty ARRAYs
Array ( ) Array ( )
When I try to upload only .mp4, I also get empty arrays
Array ( ) Array ( )
Please I need help. I do not really understand what am doing wrong. Thank you.
Advertisement
Answer
I have solved the problem. I had to edit my Php.ini file, increasing the post_max_size to 200. I also co figured my ajax post to upload the files in batches. After uploading file 1, it will check the responseText in the eventCompleteHandler(). If it reruns success, then check if another file is selected and post it else check for another file and post it. If no other files, then report.. Upload successful and completed.