-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

The php.ini on the server as of in PHP 5.3.0 may exclude cookies from $_REQUEST, so it might be the php.ini on the server that needs to be edited correspondently.

If You don't have ability to edit php.ini, use $_POST / $_GET etc instead of $_REQUEST.

If You don't know which way Your variable is sent, use something like this:

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

It might also be the flush() function that does not work due to php.ini settings. See user comments under php.net flush() reference - some recommendations about how to edit php.ini to make it work are listed there.

于 2012-10-17T12:39:29.610 回答