rick7117 Posted July 22, 2013 Share Posted July 22, 2013 I am getting a Excel error message that the file is in different format or may be corrupted when I try to open the file I download from my site. My code is follows: <?php session_cache_limiter('none'); session_start(); include "db_conn_open.php"; $filename = 'MarketBasket_Report_' . date("Y-m-d").'.xls'; header("Content-type: application/xls"); header("Content-Disposition: attachment; filename=$filename"); /* $sql = "SELECT a.ordName, b.id, Date_format(b.ordersent_timestamp,'%c/%e/%Y')as 'Order Sent', b.orderid as 'Order ID', DATE_Format( b.orderconfirmation_timestamp,'%c/%e/%Y' ) as 'Order Confirmation', b.ponumber as PO FROM orders as a inner join PunchOutLog as b on a.OrdId = b.OrderId"; */ if(isset($_GET['startdate']) && !empty($_GET['startdate']) && isset($_GET['enddate']) && !empty($_GET['enddate'])){ $start_date = date('m/d/Y',strtotime($_GET['startdate'])); $end_date = date('m/d/Y',strtotime($_GET['enddate'])); $sql = "SELECT a.ordName, b.id, Date_format(b.ordersent_timestamp,'%m/%d/%Y')as 'Order Sent', b.orderid as 'Order ID', DATE_Format( b.orderconfirmation_timestamp,'%m/%d/%Y' ) as 'Order Confirmation', b.ponumber as PO FROM orders as a inner join PunchOutLog as b on a.OrdId = b.OrderId WHERE Date_format(b.ordersent_timestamp,'%m/%d/%Y') > '$start_date' and Date_format(b.ordersent_timestamp,'%m/%d/%Y')< '$end_date' ORDER BY b.ordersent_timestamp DESC"; } /*else { $sql = "SELECT a.ordName, b.id, Date_format(b.ordersent_timestamp,'%c/%e/%Y')as 'Order Sent', b.orderid as 'Order ID', DATE_Format( b.orderconfirmation_timestamp,'%c/%e/%Y' ) as 'Order Confirmation', b.ponumber as PO FROM orders as a inner join PunchOutLog as b on a.OrdId = b.OrderId"; } */ $sep = "\t"; $result=mysql_query($sql); for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) { $schema_insert .= "NULL".$sep; } elseif ($row[$j] != ""){ $schema_insert .= "$row[$j]".$sep; } else { $schema_insert .= "".$sep; } } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/280396-content-type-header-giving-me-error/ Share on other sites More sharing options...
Muddy_Funster Posted July 22, 2013 Share Posted July 22, 2013 That's MS Excel embeds it's own meta data into the file. You just need to accept that this message will apear and that you will need to click to open anyway when the propt comes up. You could just save as CSV and have Excel open the CSV, that would avaoid the warning. Quote Link to comment https://forums.phpfreaks.com/topic/280396-content-type-header-giving-me-error/#findComment-1441670 Share on other sites More sharing options...
requinix Posted July 22, 2013 Share Posted July 22, 2013 You could just save as CSV and have Excel open the CSV, that would avaoid the warning.That. Don't tell people you're sending Excel files when you're actually sending CSV files. Quote Link to comment https://forums.phpfreaks.com/topic/280396-content-type-header-giving-me-error/#findComment-1441690 Share on other sites More sharing options...
rick7117 Posted July 23, 2013 Author Share Posted July 23, 2013 thanks, as csv it is downloading through excel. The next thing I have to work on is to have the formatting corrected to look right. Quote Link to comment https://forums.phpfreaks.com/topic/280396-content-type-header-giving-me-error/#findComment-1441844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.