我一开始就遇到了 PhP 文件上传进度监视器的问题.
I have a problem with PhP File Upload progress monitor at the very start.
首先,这里是相关的 PhP.ini 设置(指令、本地值和主值):
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_
这是表格(简化版):
<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 脚本),如:
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);
...
...
upload_status.php 只是回应 $_SESSION 数组.我还在 form-php 中设置了一个测试会话变量,以确保 AJAX(通过 upload_status.php)选择该会话变量.确实如此.但不是 $_SESSION 数组中上传状态的标志(无变量/索引)!文件被上传.我确保文件足够大,以便 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.
我之前从未实现过 PhP 文件上传进度条,所以我想知道我是否遗漏了什么.一旦我在上传中获得一个状态点,我就可以完成其余的工作.
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.
谢谢
可能存在一些问题,我已经列出了其中的几个.
There could be some issues, I have listed down few of them.
这可以帮助您跟踪进度条http://pecl.php.net/package/uploadprogress
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.
这篇关于PhP 5.4 中的 PhP 上传进度不起作用.会话变量未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!