Last active
January 14, 2019 23:14
-
-
Save vincentkoc/9806010 to your computer and use it in GitHub Desktop.
PHP Rules for CSV exports for UTF-8 and old browsers. Dynamic Exporting with rules to support each type of format which is extendable to call a parser on inputs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Do Download Headers if we have nothing else to show | |
if($uri_page[$no] == 'export'){ | |
//Universal | |
ini_set('zlib.output_compression','Off'); | |
if($uri_page[$no+1] == 'csv'){ | |
//CSV | |
header('Content-Encoding: UTF-8'); | |
header('Content-type: text/csv; charset=UTF-8'); | |
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
header('Content-Disposition: attachment; filename="adtrafik_export.'.$uri_page[$no+1].'"'); | |
//IE FIX | |
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Pragma: public'); | |
}else{ | |
header('Pragma: no-cache'); | |
} | |
echo "\xEF\xBB\xBF"; // UTF-8 BOM | |
}else{ | |
//JSON | |
header('Content-Type: ' . 'text/plain'); | |
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
header('Content-Disposition: attachment; filename="adtrafik_export.'.$uri_page[$no+1].'"'); | |
//IE FIX | |
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Pragma: public'); | |
}else{ | |
header('Pragma: no-cache'); | |
} | |
}//END IF TYPE CSV | |
}//END IF EXPORT | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment