在PHP 5.4 PHP上传进度不工作。没有设置会话变量 [英] PhP Upload progress in PhP 5.4 is not working. Session variables not set
问题描述
我有一个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阿贾克斯code,在同一个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数组。我还设置形式,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.
- 在Web服务器的请求缓冲区已经为这个被禁用的正常工作,否则PHP可以看到文件的上传一次完全上传。
- 在此功能不起作用,当你的网络服务器通过FastCGI的运行PHP。
- 请不要忘了,该会话已经生成表单之前被初始化,否则你将得到的会话的信息。
- 在它不会在PHP 5.3或更早的工作。
- 请注意,如果您运行code和你打印出$ _SESSSION内容[$关键]你会得到一个空数组由于该session.upload_progress.cleanup是在默认情况下,它尽快清理进度信息因为所有的POST数据已被读取。它设置为关闭或0看$ _SESSION [$关键]的内容。
这可以帮助你跟踪你的进度条 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上传进度不工作。没有设置会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!