简体   繁体   English

在某些文件上使用formData上传Ajax文件失败

[英]Ajax file upload with formData fails on some files

file upload with jQuery+formData and php works fine with some files. 使用jQuery + formData和php上传文件时,某些文件可以正常工作。 But on other, I think larger files it seems the file is cuted or something. 但另一方面,我认为较大的文件似乎已被剪切或其他内容。 The $_POST and $_FILES arrays are empty. $ _POST和$ _FILES数组为空。 I tried lot of things, but nothing helps. 我尝试了很多事情,但没有任何帮助。

Here the form: 形式如下:

    <form id="myform"  method ="post" enctype="multipart/form-data">
       <input type="file" id="file-documents" name="file" class="hidden">
    </form>

and js code: 和js代码:

        var form = $('#myform')[0];
        var data = new FormData(form);
        data.append('job', 'upload_file');

     $.ajax({
        url: 'api.php',
        type: 'POST',
        data: data,
        async: false,
        cache: false,
        processData: false, // Don't process the files
        contentType: false, // 
        success: function(data) {
            ...
        }
    });

I see following in the firebug request: 我在萤火虫请求中看到以下内容:

Source -----------------------------15933312197684 Content-Disposition: form-data; 来源----------------------------- 15933312197684 Content-Disposition:表单数据; name="file"; name =“文件”; filename="ganz alt.zip" Content-Type: application/x-zip-compressed filename =“ ganz alt.zip”内容类型:application / x-zip-compressed

PK êPEëøz ýtQ ù¥X 20140728164446766.pdfÄZù_×PÍ!âÆ AÙTG¥dµJÀ²FÔ¥-¶QÁAÐÙJ ì" ®EQµ `U|¶}ïÄ÷þ÷î½sï9ç~Ï÷|ÏØùø9»¬\\£o[VïfµÚjL¢þÆ«"¾J[½%&1Kê¯ÚÆ!5Rö~§¿j{B,oµf« þ ÿ¸/âI+·µëÖé¯b%ÂâûSR÷óâx¤þ bòþÛR÷rãVùÄNàÆm>¸÷+ýU~ ÉdÜAÎ*ðÛæÇÝ·KÕ Û{0ågãFÍt~ PK PEPEøøzyQQQ¥X 20140728164446766.pdfÄZù_×PÍ!“AÙTG¥dµJÀ²FÔ¥-¶QÁAÐÙJì“ ®EQµ U} ¬\\£o [VïfµÚjL¢þÆ«“¾J[½%&1Kê¯ÚÆ!5Rö〜§¿j{B,oµf« ÿ¸/âI+·µëöé¯b%âSRSR÷ óxäþbòþÛR÷rãVãÄNàÆm>¸÷+ ýU〜ÉdÜAÎððÛæÇÝ·KÕ0 {0ågãFÍt〜

... ...

-----------------------------15933312197684 Content-Disposition: form-data; ----------------------------- 15933312197684 Content-Disposition:表单数据; name="job" 名称=“工作”

upload_file -----------------------------15933312197684-- upload_file ----------------------------- 15933312197684--

You need to increase your max post file size. 您需要增加最大帖子文件大小。 Open up your php.ini file and find the variables post_max_size = 8M and upload_max_filesize = 2M . 打开您的php.ini文件,找到变量post_max_size = 8Mupload_max_filesize = 2M Change the values to 16M or however large you need. 将值更改为16M或所需的大小。 Be careful not to make it any larger than you really need to though. 但是请注意不要使其超出实际所需的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM