Home > Software engineering >  PHP - download a CSV file but Firefox browser detects it as Zip file
PHP - download a CSV file but Firefox browser detects it as Zip file

Time:12-09

when i download a CSV file on Firefox browser then detect it is Zip file (must be CSV)

looking at picture under

I want to it is CSV file.

this is my the code

<?php
$filename = 'example.csv';
header('Cache-Control: public');
header('Pragma: public');
header('Content-Type: application/csv; name="' . $filename. '"');
header("Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($filename));

$th = array();
$th[] = "名前";

mb_convert_variables('SJIS','UTF-8',$th);

$out = fopen('php://output', 'w');
fputcsv($out, $th);
fclose($out);

ob_get_contents();
ob_flush();
flush();

CodePudding user response:

According to enter image description here

But I don't understand yet why adding exit() has this working properly

CodePudding user response:

This "error" is related to your computer file open configuration. Maybe you checked the option to assign .csv files to this zip software, but, is easy to change the software and set another one.

  •  Tags:  
  • php
  • Related