"") { header("Content-disposition: attachment; filename=$file"); header("Content-Type: text/plain"); header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-type: application/x-msexcel; charset=utf-8"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($temp_str)); header("Pragma: no-cache"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); 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); } ?>