duanhuoyao7011 2018-02-07 14:33
浏览 64
已采纳

多文件上传不会向服务器发送任何数据

I want to upload multiple file upload. I have this on client side :

        $(document).on( "click", ".save-button", function () {

            var data = new FormData();
            data.append('title', $(this).parent().parent().find("#title_place").val());

            $.each($(this).parent().parent().find("input[type='file']")[0].files, function(i, file) {
                data.append('file', file);
            });

            $.ajax({type: "POST",
                url: 'save_view.php',
                data: data,
                success : viewSaveCallBack,
                cache: false,
                contentType: false,
                processData: false,
            });
        });

I checked all the data in the debuger, and it is working properly. To see this I displayed the value of

 $(this).parent().parent().find("#title_place").val()

And

$(this).parent().parent().find("input[type='file']")[0].files

Then, when I try to var_dump $_FILES or $_POST on server side, it's empty. Same thing with a debugger. enter image description here enter image description here

I tried also with

                data.append('files[]', file);

When I try to upload a single file (in another input, not exactly the same code), that is working fine.

The html of the input is this one :

        <input type=\"file\" multiple directory webkitdirectory allowdirs class=\"form-control input\" id=\"marzipano\">

And it is added dynamically to the DOM.

When I upload a single file, that is working fine.

It is not a duplicate of Sending multipart/formdata with jQuery.ajax since I already use a FormData object, and my code is the same as the answer. It is still not working as intended.

  • 写回答

2条回答 默认 最新

  • duanbeng1923 2018-02-07 15:53
    关注

    My code is working actually, problem was that post_max_size in the php.ini was too low.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化