-1

プログレスバー用のPHPスクリプトを書いています。

私のコード:

<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
<?php

if(isset($_REQUEST['sub']))
{
// Total processes
    $total = 10;

    // Loop through process
    for($i=1; $i<=$total; $i++){
        // Calculate the percentation
        $percent = intval($i/$total * 100)."%";

        // Javascript for updating the progress bar and information
        echo '<script language="javascript">
        document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
        document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
        </script>';

        // This is for the buffer achieve the minimum size in order to flush data
        echo str_repeat(' ',1024*64);

        // Send output to browser immediately
        flush();

        // Sleep one second so we can see the delay
        sleep(1);
    }

// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>
<form>
<input type="submit" name="sub" value="Go" />
</form>
</body>

このサーバーでテストすると、正しく動作します。しかし、このサーバーでは「プロセスが完了しました」と表示されます。Goボタンをクリックした後..

両方のサーバーで同じコーディングを使用しました...

私の間違いは何ですか?何か案が?前もって感謝します。

4

1 に答える 1

0

PHP 5.3.0 の時点でサーバー上の php.ini は から Cookie を除外する$_REQUEST可能性があるため、対応して編集する必要があるのはサーバー上の php.ini である可能性があります。

php.ini を編集できない場合は、代わりに$_POST/ etc を使用してください。$_GET$_REQUEST

変数が送信される方法がわからない場合は、次のようなものを使用します。

switch($_SERVER['REQUEST_METHOD']) {
    case 'GET': $the_request = &$_GET; break;
    case 'POST': $the_request = &$_POST; break;
    default:
}

flush()php.iniの設定により動作しない機能もあるかもしれません。php.net flush() リファレンスの下にあるユーザー コメントを参照してください。php.iniを編集して機能させる方法に関する推奨事項が記載されています。

于 2012-10-17T12:39:29.610 に答える