soft genic
soft genic

Reputation: 2056

Display image before for loop execution

Following is my script in which i am converting xls to csv . The problem i am facing no matter what is mentioned before the piece of code of the for loop, it runs first.Kindly let me know how can i display the image from the following script first and then run the loop script:

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

Upvotes: 0

Views: 184

Answers (1)

Waseem Senjer
Waseem Senjer

Reputation: 1048

You can use flush() function

it pushes current output all the way to the browser.

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

Upvotes: 3

Related Questions