Iam trying to generate an excel file for down load with this code,but nothing is going right;
if(!isset( $_POST['data_set'])){$err='ERROR: Please select a data type!';} else if(empty($err)){ $begin_date=$_POST['outreach_date']; $end_date=$_POST['outreach_date2']; $colnames=array("Title","Project date","Description","Mandate","Project Type","Agency","Perfomance indicator"); $field_cnt = count($colnames); header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=export.xls"); header("Pragma: no-cache"); header("Expires: 0"); //$totalRecord=$field_cnt; for ( $i = 0; $i < $field_cnt; $i++ ) { echo $colnames[$i]. "\t"; }print("\n"); }else{ // if(isset($err)){ echo json_encode( array( "success" => "0", "Error" => htmlentities($err), ) ); }
why am i failing to get the file download?is it because of other data above the headers??
if i do this below, it all works fine.why is it that when i include any data validation it fails to work/?
$colnames=array("Title","Project date","Description","Mandate","Project Type","Agency","Perfomance indicator"); $field_cnt = count($colnames); for ( $i = 0; $i < $field_cnt; $i++ ) { $header .= $colnames[$i]. "\t"; } // allow exported file to download forcefully header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=devzone_co_in_export.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data";
Edited by Qreen, 04 February 2015 - 06:50 AM.