Export CSV file Error in IE but Works in FF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shyamkodase
Forum Newbie
Posts: 3
Joined: Thu Dec 07, 2006 7:38 am

Export CSV file Error in IE but Works in FF

Post 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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply