$host = "localhost"; $user = "root"; $passwd = "j4141290"; $dbname = "present"; $link = mysql_connect($host,$user,$passwd); mysql_select_db($dbname, $link); mysql_query("set names tis620"); function cover_date_thai($txtdate) { $year=substr("$txtdate",0,4); //$year=$year+543; return substr($txtdate,6,2)."/".substr($txtdate,4,2)."/".$year; //return (int)$day." ".$month." ".$year; } function create_csv_file($querystring, $txtname) { $file = "/var/www/ssko_presents/file_presents/" . $txtname; $temp_str = ""; if ($temp_str > "") { header("Content-disposition: attachment; filename=$file"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($temp_str)); header("Pragma: no-cache"); header("Expires: 0"); echo $temp_str; } $result_csv=mysql_query($querystring); $fh=fopen($file,"w+") or die ("unable to open file"); //note that this APPENDS not overwrites while($row=mysql_fetch_assoc($result_csv)): foreach ($row as &$val): $val = str_replace('"', "'", $val); endforeach; fputcsv($fh, $row, ",", '"'); //$temp_str .= '"'.implode('","',$row).'"\n\r'; $t_temp_str = '"'.implode('","',$row).'"'. chr(13) . chr(10); //used for the non file based download endwhile; fclose($fh); } ?>
|