PHP Exported csv file download doesn't start? -


this question has answer here:

so have piece of code here reads data database , should prompt me "open/save as" window doesn't. idea problem might be? echo-es results download window doesn't appear.

    <?php/* mb_http_output('utf-8'); mb_http_input('utf-8'); mb_language('uni'); mb_regex_encoding('utf-8'); ob_start('mb_output_handler'); header('content-type: text/html; charset=utf-8');*/ ?> <?php   $conn = mysql_connect('localhost', 'xxxx', 'xxxx') or die(mysql_error()); mysql_select_db('nooruse', $conn) or die(mysql_error($conn));  $query = sprintf('select osakond osakond, soetusaasta, it_number, tooteruhm, mudeli_nimetus, sn, riigivara_nr, inventaari_nr, maja, ruum, vastutaja, markus norse5_proov'); $result = mysql_query($query, $conn) or die(mysql_error($conn));  header('content-type: text/csv'); header('content-disposition: attachment;filename=export.csv');  $row = mysql_fetch_assoc($result); if ($row) {     echocsv(array_keys($row)); }  while ($row) {     echocsv($row);     $row = mysql_fetch_assoc($result); }  function echocsv($fields) {        echo $query ,"<br>";     $separator = '';     foreach ($fields $field) {         if (preg_match('/\\r|\\n|,|"/', $field)) {             $field = '"' . str_replace('"', '""', $field) . '"';         }         echo $separator . $field;         $separator = ',';     }     echo "\r\n"; } ?> 

thanks in advance!

you're not allowed have output before send headers via header(). includes whitespace before first <?php , newline between ?> , <?php.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -