进度条与APC和Codeigniter -麻烦与IE和Chrome

Progress bar with APC and Codeigniter - Trouble with IE and Chrome

本文关键字:麻烦 IE Chrome Codeigniter APC      更新时间:2023-09-26

我正在尝试使用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&eacute;l&eacute;ctionnez un fichier</label><br />
<input type="file" name="userfile" id="userfile" size="20" />
&nbsp;
<button class="btn btn-primary" type="submit" name="submit" id="submit" value="Submit"><span class="icon-upload"></span>&nbsp;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&eacute;l&eacute;charg&eacute;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&eacute;l&eacute;charg&eacute;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');