0

I tried to make script ajax + php to upload files using put method, it is uploading, but the problem is, it makes the uploaded file no longer accessible.

sample original file :

test

uploaded file :

------WebKitFormBoundaryfHeuzHdIUxsjGOUb
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

test

------WebKitFormBoundaryfHeuzHdIUxsjGOUb--

as you can see if file is video/zip or any other file, it sure will broken.

here is my code

sendFile: function(files, index) {
                            if ($('a[data-parent="#accordion"]').size() != 0) {
                    var numRow = $('a[data-parent="#accordion"]').size();
                }
                else {
                    var numRow = index;
                }
                var progress = $('li[data-image="'+files[index].name+'_'+files[index].unique+'"]');

                // File size validation
                if (files[index].size >= 49999999) { // 49.999.999 = 50Mb max
                    progress.html('<strong style="color: red;">Cancelled</strong>');
                    progress.parent().next().html('File Size Exceeded! (MAX:50Mb)');
                    console.log("File size Exceeded!");
                    dragNdrop.prepare(files, index+1);
                    return false;
                }
                // begin upload

                var formData = new FormData();
                formData.append('file', files[index]);

                var xhr = new XMLHttpRequest();
                xhr.open('put', 'ajax/upload', true);
                xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                xhr.setRequestHeader("X-File-Name", files[index].unique);
                xhr.onload = function() {
                    progress.find('.filestatus').html('<img src="assets/img/wait.gif">').fadeIn(200);
                }
                xhr.upload.onprogress = function (event) {
                       // too long to display
                        }
                        xhr.send(formData);

how can i upload file using my script without broken it ?

thanks in advance!

robbiejobs
  • 45
  • 3
  • 6

0 Answers0