【问题标题】:How to make session.upload_progress work with PHP 5.4 + nginx如何使 session.upload_progress 与 PHP 5.4 + nginx 一起工作
【发布时间】:2013-05-31 14:46:18
【问题描述】:

我写了一个 PHP 表单来上传这样的文件

<form action="upload.php" method="POST" enctype="multipart/form-data">    
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />   
<input type="file" name="file1" />   
<input type="file" name="file2" />   
<input type="submit" />    
</form>

(来自这里:http://php.net/manual/en/session.upload-progress.php

现在我想通过 ajax(get) 获取我的上传进度,所以我创建了一个 iframe 并将我的表单定位到这个 iframe
然后,我创建另一个 php 文件来获取状态...

<? php
$key=ini_get("session.upload_progress.prefix")."FORM NAME";
$_SESSION[$key]...

...嗯.. $_SESSION 在 nginx-1.4.1 上为空,但此方法适用于我的 apache (我对每个服务器使用相同的脚本)
这是 session.upload_progress 的 php.ini

session.upload_progress.cleanup 开启

session.upload_progress.enabled 开启

session.upload_progress.freq 1%

session.upload_progress.min_freq 1

session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS

session.upload_progress.prefix upload_progress_

如何解决...

【问题讨论】:

    标签: php file-upload nginx progress


    【解决方案1】:

    Nginx 会缓冲请求正文(包括文件上传),因此 PHP 仅在浏览器完成发送文件后才能看到文件,从而使该功能无用。

    不幸的是,目前无法在 nginx 中禁用请求正文缓冲。有人创建了nginx patches

    另一种方法是使用这个 nginx 模块:[HttpUploadProgressModule](http://wiki.nginx.org/HttpUploadProgressModule

    【讨论】:

      猜你喜欢
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      • 2012-05-25
      • 2019-09-08
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多