进度条与APC和Codeigniter -麻烦与IE和Chrome
Progress bar with APC and Codeigniter - Trouble with IE and Chrome
我正在尝试使用Codeigniter和APC制作进度条。
这是我的表格:
<form method="post" action="" id="upload_file" enctype="multipart/form-data" target="result_frame">
<input type="hidden" value="<?php echo uniqid(); ?>" id="progress_key" name="APC_UPLOAD_PROGRESS" />
<p><label for="userfile">Séléctionnez un fichier</label><br />
<input type="file" name="userfile" id="userfile" size="20" />
<button class="btn btn-primary" type="submit" name="submit" id="submit" value="Submit"><span class="icon-upload"></span> Valider</button></p>
当用户点击提交按钮时,它将触发上传过程。下面是我的check-progress函数:
function checkProgress() {
$.ajax({
type: "POST",
url: "/fbe_upload/index.php/fbeupload/upload_progress",
async: true,
dataType: "json",
data: {
session_unid: $('#progress_key').val()
},
//Success
success: function(data) {
//Progress
liveProgress = data.progress;
//Progress bar
$('#progressBar-' + idRow).attr("class", "progress progress-striped active");
$('#progressBar-' + idRow + " div.bar").css("width", parseInt(liveProgress) + "%");
$('#td-pc-' + idRow).html(parseInt(liveProgress) + "% téléchargés");
//END success
},
//Error
error: function() {
//Erreur
alert("Error.");
}
//Ajax END
});
//Progress < 100
if (liveProgress < 100) {
//Call function again
setTimeout(checkProgress, 800);
}
//Else
else if (liveProgress === 100) {
//Progress bar
$('#progressBar-' + idRow).attr("class", "progress progress-striped active");
$('#progressBar-' + idRow + " div.bar").css("width", "100%");
$('#td-pc-' + idRow).html("100% téléchargés");
//Message
$('#td-filename-' + idRow).html("<i>Finalisation en cours...</i>");
//This function manage the end of the upload process (message, buttons,...)
setTimeout(endUpload, 4800);
//Else END
}
else {
setTimeout(checkProgress, 1200);
}
//checkProgress END
}
这是我的PHP文件:
function upload_progress() {
//Key
$key = 'upload_' . $_POST['session_unid'];
$status = apc_fetch($key);
//Progress
$cal = ceil($status['current'] / $status['total'] * 100);
echo json_encode(array('progress' => $cal));
}
所以,当用户点击"提交"时,他的文件被上传(我使用这个来编写我的上传函数),函数checkProgress在1.5秒后被调用。
使用Firefox,一切都很好。我有正确的值,进度条也会像我想要的那样运行。使用IE和Chrome,它不能正常工作:对于"进度"值,IE总是返回420和Chrome 410。所以,这就像上传过程已经完成,但它不是。顺便说一下,这些值不对应于文件的大小或其他东西。我不明白为什么Firefox可以计算并返回正确的值,而其他浏览器却不行。
WITH FIREFOX:
Array
(
[total] => 791309142
[current] => 113631842
[filename] => up.rar
[name] => userfile
[done] => 0
[start_time] => 1370864635.9486
)
WITH CHROME:
Array
(
[total] => 410
[current] => 410
[rate] => 22777015.099338
[filename] =>
[name] => userfile
[cancel_upload] => 4
[done] => 1
[start_time] => 1370864408.3726
)
在我的php.ini中有:
extension=php_apc.dll
[APC]
apc.enabled = 1
apc.max_file_size = 5000M
apc.rfc1867 = On
apc.mmap_file_mask = C:'wamp'tmp'file_template_%s.tmp
apc.shm_segments = 1
apc.shm_size = 64M
apc.stat=1
有人有什么建议吗?我将不胜感激。谢谢!
我想这是IE缓存问题
尝试用cache
标记$.ajax
请求参数,设置false
或/并为请求添加时间戳
function checkProgress() {
$.ajax({
type : "POST",
url : "/fbe_upload/index.php/fbeupload/upload_progress?t=" + (new Date().getTime()),
cache : false,
// ....
并为/fbe_upload/index.php/fbeupload/upload_progress
路由添加无缓存标头
header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 如何在读取XLS/XLSX本地文件时,使用IE的javascript代码启用未标记为安全的ActiveX控件
- jQuery blueimp文件上传:将N-1个文件上传到IE中的服务器
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- 设置倒计时计时器,IE出现问题
- 仅在IE中,javascript中的时区名称不正确
- 在IE中加载Firebug Lite时出现问题
- 为什么我得到错误IE修剪方法是't支持
- IE中的CSS翻转动画:翻转的一面显示镜像内容
- 通过具有IE<11
- IE在将字符串转换为日期时从日期中删除4小时
- 列表样式在IE中未设置为none,但在IE中适用
- IE/Chrome中未定义的函数,但Firefox中没有
- Jquery Modal表单登录与AJAX-ASP经典上的IE 9
- window.opener.document在ie中不起作用
- 在Firefox和IE中获取CSS属性时遇到麻烦
- 进度条与APC和Codeigniter -麻烦与IE和Chrome
- 麻烦在重定向到另一个页面后,从IE ajax post (Description Inside)
- 有麻烦与我的代码工作的IE或火狐