Page 1 of 1

Export CSV file Error in IE but Works in FF

Posted: Fri Sep 14, 2007 12:47 am
by shyamkodase
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 

I had  a requirement of exporting the  contents of a table in to  CSV format ;   i succeeded in exporting the data in CSV format in Mozilla ... but when i run the same script in IE its not exporting the data!!!!!      

when i run the script in IE i get this dialogue box while exporting 

"Internet Explorer was not able to open this internet site the requested site is either unavailable or can not be found please try again later"

but when i run the same script in MOZILLA  everything   works perfectly 

 This is the Code  that i am using to export the table contents  
----------------------------------------------------------------------------------------

Code: Select all

$date=date("Y-m-d");
$file=$_GET['type']."_".$date.".csv"; 
set_time_limit(300);
header('Content-Description: File Transfer'); 
header('Content-Type: application/force-download'); 
header('Content-Length: ' . filesize($file)); 
header('Content-Disposition: attachment; filename=' . basename($file)); 
header("Content-Type: text/csv");
$strarr = '';
$headercsv = "COMPANY NAME,CUSTOMER NAME,COUNTRY,STATUS,EMAIL-ID,ACTIVE";
$separator = chr(13).chr(10);
$strarr = $headercsv.$separator;
$query_status	  =	"SELECT CC.active,CC.name as company_name, CC.country, CC.email AS comp_email, CCC.fullname as customer_name, CCC.email AS cust_email FROM `crm_customer` CC, `crm_custcontact` CCC WHERE  status in ('".$status."') AND CC.cust_id = CCC.cust_id";
$run_query_status =	mysql_query($query_status)or die(" 1: Query failed: " . mysql_error());
$countofrows=mysql_num_rows($run_query_status);
$check=ceil(($countofrows/60));
$checklimit=0;
  while($checklimit <= $check)
 {
    $limit=$checklimit*60;
    $query_status ="SELECT CC.active,CC.name as company_name, CC.country, CC.email AS comp_email,      CCC.fullname as customer_name, CCC.email AS cust_email FROM `crm_customer` CC, `crm_custcontact` CCC  WHERE  status in ('".$status."') AND CC.cust_id = CCC.cust_id limit $limit,60";
     $run_query_status =	mysql_query($query_status)or die(" 1: Query failed: " . mysql_error());
    while($rs = mysql_fetch_array($run_query_status)) 
     { 
        $comp_name=$rs['company_name']; 
	$country=$rs['country'];   
	$emailids=$rs['cust_email']; 
	$cust_name=$rs['customer_name'];
	$active=$rs['active'];
	$comp_name=str_replace(",","",$comp_name);
        $country=str_replace(",","",$country);
	$emailids=str_replace(",","",$emailids);
	$cust_name=str_replace(",","",$cust_name);
       $strarr.=$comp_name.",".$cust_name.",".$country.",".$status.",".$emailids.",".$active.",".$separator;
     }//while 
   $checklimit++; 
  }
  echo $strarr;
exit();
---------------------------------------------------------------------------------------

Please tell me where i went wrong and also send me the site where i can research more on Exporting to CSV files php

Thanks in advance
Shyam Kodase


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Sep 14, 2007 1:13 am
by s.dot
Since PHP is server side, the problem most likely exists in the HTML/CSS/JavaScript.

Sometimes IE does that to me though, and I restart my machine and I'm good to go. Unexplainable.

Posted: Fri Sep 14, 2007 2:59 pm
by pickle
This is usually a header issue (or at least, that's the case in my experience).

Sending 2 "Content-Type" headers probably isn't helping matters.
When I want a forced download, "Content-Type: application/octet-stream" always seems to work for me.

As for more research, try here: http://www.google.com