【发布时间】:2014-03-09 07:28:41
【问题描述】:
我一开始就遇到了 PhP 文件上传进度监视器的问题。
首先,这里是相关的 PhP.ini 设置(指令、本地值和主值):
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_
这是表格(简化):
<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>
我有 JQUERY Ajax 代码,在同一个 PhP 文件中(当然,作为一个 JS 脚本),如:
$('#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);
...
...
upload_status.php 简单地回显了 $_SESSION 数组。我还在 form-php 中设置了一个测试会话变量,以确保 AJAX(通过 upload_status.php)选择该会话变量。确实如此。但不是 $_SESSION 数组中上传状态的标志(无变量/索引)!文件被上传。我确保文件足够大,以便 5000 毫秒足以报告一些中间状态。
我以前从未实现过 PhP 文件上传进度条,所以我想知道我是否遗漏了什么。一旦我在上传中获得一个状态点,我就可以完成其余的工作。
谢谢
【问题讨论】:
-
你查看了那个 rifht php.net/manual/en/session.upload-progress.php
-
@dollarVar。我已经阅读了它并在您的消息之后再次阅读它只是为了看看我是否遗漏了什么。仍然没有运气。我犯了一些错误,但更早地纠正了它们。我知道这一定很简单。我确实赞成你的建议。
-
好吧,就我所见,你不能回显整个数组。 upload_status.php 只是简单地回显了 $_SESSION 数组。 你的表单也有错误。
<?echo应该是<?php echo或<?=。 (如果启用了开放式短标签stackoverflow.com/questions/200640/…) -
据我从谷歌上了解到 FastCGI 不支持此功能,您可以尝试使用客户端解决方案:uploadify.com/documentation/uploadifive/onprogress
标签: php jquery ajax file-upload