Upload document files using file api

847 views Asked by At

Iam using below code to upload files using jquery fileapi.Images uploading fine but documents(doc,xls) files are not uploading.In console it shows 'empty files'(wriiten in js code).Please help.

in images upload, test.php file is called but others it does not call this file.am i missing anything?

Header part

   <script> 
        FileAPI = {
            debug: false,
            pingUrl: false,
            staticPath: 'dist/'
        };
    </script>

    <script type="text/javascript" src="dist/FileAPI.min.js"></script>      
    <script type="text/javascript" src="jquery.js"></script>

dist folder contains

FileAPI.flash.image.swf,
FileAPI.flash.swf,
FileAPI.min.js,

Javascript functions

function handleAllFileTypesSelect(evt)
{

     {

        var files = FileAPI.getFiles(evt);

        FileAPI.filterFiles(files,function(file, info) {
            image_mime = file.type;

            console.log(info);

            if (/doc|docx|pdf|txt|jpg|jpeg|gif|png|xls|xlsx|ppt|pptx|ods|zip|csv|/.test(file.type) && info) {

                return info.width >= 1 && info.height >= 1;
            } else {

                return file.size > 0;
            }
        },

        function(fileList, ignor) {

            if (ignor.length) {
                console.log('ignor length:' + ignor.length);
            }
            if (!fileList.length) {
                console.log('empty file list');
                return;
            }

            // do preview
            var fileList = FileAPI.filter(fileList, function(file) {
                return /doc|docx|pdf|txt|jpg|jpeg|gif|png|xls|xlsx|ppt|pptx|ods|zip|csv|/.test(file.type);
            });


            j = 0;

            FileAPI.each(fileList,function(imageFile) {
                FileAPI.upload({
                    url : 'test.php',
                    data : {
                        type : 'pdf',
                        file_prefix : 'image_',
                        file_length : fileList.length,

                    },
                    files : {
                        files : FileAPI.filter(fileList,function(file) {
                            return !/doc|docx|pdf|txt|jpg|jpeg|gif|png|xls|xlsx|ppt|pptx|ods|zip|csv|/.test(file.type);
                        }),
                        child_attachments : imageFile
                    },
                    complete : function(err, xhr) {
                        if (!err) {
                            if ((xhr.responseText).search(/ERROR: File/gi) == -1) {

                                var response_text_value = xhr.responseText;
                                response_text_value = response_text_value.replace(/\s/g,'');
                                alert(response_text_value);
                                //$('#ifileList').val(val + ','+ response_text_value);
                                //$('input[type="submit"]').removeAttr('disabled');
                            }
                        }
                    }
                                                                                                                                });
                    FileAPI.Image(imageFile).preview(100, 75).get(function(err,image) {
                        if (err) {
                        } else {

                        }
                    });
                });
            }
        );
    } // else
}   

</script>   

HTML

 `<form id="observation_form" class="appnitro"  method="post" action="test.php" enctype`="multipart/form-data">

        <span class="file-wrapper js-fileapi-wrapper" id="span-image"  style="position: relative;">
                          <input id="logo" name="child_attachments[]" data-preview_id="preview_list" type='file' accept="" multiple  />
                          <span class="button">Attachments</span>
                        </span>
        </form>

    <script type='text/javascript'>
    document.getElementById('logo').addEventListener('change', handleAllFileTypesSelect, false);
    </script>
1

There are 1 answers

0
RubaXa On
  1. http://filext.com/faq/office_mime_types.php
  2. Invalid regular expression (always true), delete the last pipe.