duanjia3187 2014-02-11 13:22
浏览 56
已采纳

PhP 5.4中的PhP上传进度无效。 会话变量未设置

I have a problem with PhP File Upload progress monitor at the very start.

First, here are the relevant PhP.ini settings (Directive, Local Value and Master Value):

     session.upload_progress.cleanup    On  On
     session.upload_progress.enabled    On  On
     session.upload_progress.freq   1%  1%
     session.upload_progress.min_freq   1   1
     session.upload_progress.name   PHP_SESSION_UPLOAD_PROGRESS  PHP_SESSION_UPLOAD_PROGRESS
     session.upload_progress.prefix upload_progress_    upload_progress_

Here is the form (simplified):

     <form id="fileupload" style="position:relative;" target="iframe_fileupload" action="http://www.athiyoga.org/testupload.php" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="<?echo ini_get("session.upload_progress.name");?>" value="first"/>
             <input type="file" name="file_1">
            <button type="submit" >Start Submit</button>
      </form>

I have JQUERY Ajax code, in the same PhP file (of course, as a JS script), as in:

    $('#fileupload').submit(function(event){

    //UPDATED THIS PART after reading: http://stackoverflow.com/questions/19336610/delay-in-populating-session-upload-progress-data
    //POSTING the magic variable PHP_SESSION_UPLOAD_PROGRESS during status inquiry too

       var params = {PHP_SESSION_UPLOAD_PROGRESS:"first", some_var:20 };
       var data_params = jQuery.param( params );
       setTimeout(function(){
              upload_promise = $.ajax({
                url: 'upload_status.php', 
                data: data_params,
                dataType: 'html',
                type    : 'POST',
                cache   : false 
             });
             $.when(upload_promise).done(function(status_response){
                   $('#response_status').html(status_response);
             });
        },5000);
      ...
      ...

The upload_status.php simply echoes the $_SESSION array. I also set a test session variable in the form-php to make sure that the AJAX (thru upload_status.php) picks that session variable. It does. But not a sign (no variable/index) of the upload status in the $_SESSION array! The files get uploaded. I made sure that the files are big enough so that the 5000ms is sufficient to report some intermediate status.

I have never implemented PhP file upload progress bar before so I wonder if I am missing something. Once I get one status-point in the upload, I will be able to do the rest.

Thanks

  • 写回答

1条回答 默认 最新

  • dsajdgjadwqe3247382 2014-02-18 10:57
    关注

    There could be some issues, I have listed down few of them.

    • The web server's request buffering has to be disabled for this to work properly, else PHP may see the file upload only once fully uploaded.
    • This feature doesn't work, when your webserver is running PHP via FastCGI.
    • Don't forget, that the session has to be initialized before the form is generated, otherwise you will get no information in the session.
    • It won't work in PHP 5.3 or earlier.
    • Note that if you run that code and you print out the content of $_SESSSION[$key] you get an empty array due that session.upload_progress.cleanup is on by default and it cleans the progress information as soon as all POST data has been read. Set it to Off or 0 to see the content of $_SESSION[$key].

    This can help you to track your progress bar http://pecl.php.net/package/uploadprogress

    I hope this will help you to dig out the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题