Подтвердить что ты не робот

Индикатор выполнения с APC и Codeigniter - проблема с IE и 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&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>  

Когда пользователь нажимает кнопку отправки, он запускает процесс загрузки. Вот моя функция проверки:

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));

}

Итак, когда пользователь нажимает "отправить", его файл загружается (я использовал this, чтобы написать мою функцию загрузки) и функция checkProgress вызывается через 1,5 с.

В Firefox все работает нормально. У меня есть правильные значения, и индикатор выполнения работает так, как я хочу. С IE и Chrome он работает неправильно: для значения "Progress" IE всегда возвращает 420 и Chrome 410. Таким образом, процесс загрузки уже завершен, но это не так. Кстати, эти значения не соответствуют размеру файла или что-то еще. Я не понимаю, как возможно, что Firefox вычисляет и возвращает правильное значение, а не другие браузеры.

С FIREFOX:

Array
(
    [total] => 791309142
    [current] => 113631842
    [filename] => up.rar
    [name] => userfile
    [done] => 0
    [start_time] => 1370864635.9486
)

С ХРОМОМ:

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

Есть ли у кого-нибудь предложение? Он будет очень признателен. Спасибо!

4b9b3361

Ответ 1

Я думаю, что это проблема кеша IE

попробуйте указать $.ajax параметры запроса с помощью cache установить a 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 route

header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');