1

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...
    [video] => undefined
    [audio] => undefined
)
Array
(
    [doc] => Array
        (
            [name] => Design and Implementation of a Web.docx
            [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
            [tmp_name] => C:\wamp64\tmp\php9185.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.

  • You might need to "chunk" large file sizes. I'd suggest looking into a library that does the deed. You can always study their code if you prefer homegrown. I've used "plupload" in the past. Does a good job at "chunking". – GetSet Jan 15 '21 at 23:30
  • does the video alone work? Is it a filesize problem (as @GetSet mentioned already) maybe? There's a setting in php for [maximum upload file size](https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size). What php backend are you working with? – Jeff Jan 16 '21 at 00:28
  • @Jeff, NO! The video alone does not work. Just documents only are uploaded. I am using php 7.2+ on WAMP server. The file is not even uploaded. Because, I have manually done ini_set maximum_upload_file_size and the rest of the settings. – Easytime Games Jan 16 '21 at 13:38

1 Answers1

0

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.