ruạṛ
<?php /** * Output customer details to .csv which can then be downloaded * @version 0.9 * @author Robert Urquhart <programmer@activatedesign.co.nz> * @package WEP-CMS */ session_start(); require_once 'scripts-includes/universal.php'; require_once 'scripts-includes/display.php'; $connID= connect_to_db(); $orders = mysql_query("select customer_name, customer_phone, customer_email, delivery_address from orders order by customer_name") or die(mysql_error()); $filename = DOC_ROOT.'/admin/temp/customers-'.date('Y-m-d').'.csv'; $f = fopen($filename,'w'); //get row headings $r=mysql_fetch_assoc($orders); $h = array_keys($r); for($i=0;$i<count($r);$i++) { $h[$i] = ucfirst(str_replace('_',' ',$h[$i])); } fputcsv($f,$h); mysql_data_seek($orders,0); //get rows while($r=mysql_fetch_row($orders)) { for($i=0;$i<count($r);$i++) { $j = preg_replace('/((\r\n)|\n)+/',', ',$r[$i]); $r[$i] = str_replace('"',"'",html_entity_decode($j,ENT_QUOTES)); } fputcsv($f,$r); } fclose($f); //echo file_get_contents($filename); //readfile($filename); //* ob_start(); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header('Content-Type: text/csv'); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); ob_end_flush(); // */ //clean up unlink($filename); exit; ?>
cải xoăn