循环执行前显示图像

时间:2012-12-09 10:04:22

标签: php

以下是我的脚本,我将xls转换为csv。我面临的问题无论在for循环的代码片段之前提到什么,它都先运行。请告诉我如何首先显示以下脚本中的图像然后运行循环脚本:

<body>

asdjasldjasdlj // Even this text gets load after execution of for loop
<!-- Progress information -->
<div id="information" style="width"><img src="images/L.gif" /></div>

<?php 
     require_once 'lib/excel_reader2.php';
    $excel = new Spreadsheet_Excel_Reader();
    $excel->setOutputEncoding('UTF-16');
    $excel->read('Student2.xls');
    $x=1;
    $sep = ",";

   $nbSheets = count($excel->sheets);
  echo $x." -  ".$nbSheets;

  $total = $nbSheets;

for($i = 0; $i < $nbSheets; $i++) {
           ob_start();
    while($x<=$excel->sheets[$i]['numRows']) {
        $y=1;
        $row="";
        while($y<=$excel->sheets[$i]['numCols']) {
            $cell = isset($excel->sheets[$i]['cells'][$x][$y]) ? $excel->sheets[$i]['cells'][$x][$y] : '';
            $row.=($row=="")?"\"".$cell."\"":"".$sep."\"".$cell."\"";
            $y++;
        } 
        echo $row."\n"; 
        $x++;
    }
    $x = 1; $y = 1;
    $fp = fopen("data.csv",'a');
    fwrite($fp,ob_get_contents());
    fclose($fp);
    ob_end_clean();

}

echo "CSV file created successfully";
// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';

?>
</body>

1 个答案:

答案 0 :(得分:3)

您可以使用flush()函数

它将当前输出一直推送到浏览器。

http://php.net/manual/en/function.flush.php