PHP Upload Progress Session

后端 未结 3 1362
轮回少年
轮回少年 2021-01-06 18:36

I am trying to create an upload progress bar with PHP. I saw the new feature of PHP 5.4: upload progress session.

This is my HTML code:

相关标签:
3条回答
  • 2021-01-06 18:51

    It's not possible in one POST request, you can do AJAX requests, and read session while file is uploading. After file is uploaded, the session.upload_progress.name key is removed so you are getting an empty array.

    0 讨论(0)
  • 2021-01-06 18:53

    I think it's because your form is not getting submitted, as you have return false in

    $('#upload').submit(function () {
        interval_id = setInterval(function () {
            $.ajax({
                url: "ajax/progress.php6",
                type: "POST",
                success: function (data) {
                    console.log(data);
                }
            });
        }, 200);
        return false;
    });
    

    and it initializes interval, so the page always return null as nothing is being uploaded. Try using http://www.malsup.com/jquery/form, it submits form

    0 讨论(0)
  • 2021-01-06 19:07

    Wasn't able to sort it out so I used XMLHTTPREQUEST "progress" action and that worked well. Thanks!

    0 讨论(0)
提交回复
热议问题