Hello all and thanks for reading my question.
I want someone to export a table to microsoft excel csv format and for the script to prompt them to open the file up.
The table names and data do get exported and MsExcel does open the file, the problem is when you get the file you have all this html in it as if it printed it to the calling page and you opened the calling page with excel....The actual file created in the tmp directory is correct but when the user selects to open the file from the prompt it include all the page html.
FUNCTION doBackUp( $sysParam )
{
$table = $sysParam['rldx_tbl_add']; # TableName
$tmpDir = SCRIPT_DIR_TEMP;
$out = '';
$ext = date("Y-m-d-H").'.csv';
$fields = dbListFields( $table );# ("SHOW COLUMNS FROM `$table` ")
$columns = count( $fields ); #Count the table field Names
// Put the name of all fields to $out.
FOR ($i = 0; $i < $columns; $i++) {
$l=$fields[$i];
$out .= '"'.$l.'",';
}
$out .="\n";
// Add all values in the table to $out.
$res = dbRes('SELECT * FROM `'.$table.'`' );
WHILE($row = mysql_fetch_array($res)) {
FOR($i = 0; $i < $columns; $i++) {
$out .='"'.$row["$i"].'",';
}
$out .="\n";
}
$f = fopen ($tmpDir.'export-addressbook_'.$ext,'w'); # Open file export.csv.
// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);
//header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="'.$tmpDir.'export-addressbook_'.$ext );
readfile($tmpDir.'export-addressbook_'.$ext );
}
The file create in $tmpDir contains the following
"id","gid","couple","firstname","lastname","address","suite","postalcode","city","province","country","home","mobile","work","work2","fax","email","email2","email3","yahoo","msn","icq","website","profile","profile_1","profile_2","profile_3","profile_4","profile_5","comments","aim","skype","jabber","gtalk","lat","lng",
"1","5","1","Sam","Margarita","","","","","","","","","","","","painter99@jjjjjj.com","","","","","","","1_sam_marg.jpg","1_1_sam_marg.jpg","1_2_sam_marg.jpg","1_3_sam_marg.jpg","","","","","","","","","",
"2","5","1","Shannie","Dan","","","","","","","","925.457.7657","","","","jcksorbetter@jjjjjj.com","shannie@jjjjjjj.com","w@yahoo.com","","","","","1_shannie.jpg","","","","","","","","","","","","",
However, when I select to open the file from the web prompt i.e. do you want to save the file or open the file......
I get the content above but it has all this html in it
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<!-- ========== [START] admin_adm_general_header.html ============ -->
<head>
<title>Rolodex 1.1 home:</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta name="robots" content="noindex
<meta name="distribution" content="IU" />
<meta name="revisit-after" content="15 days" />
<LINK href="http://localhost/dev/template_eng/templates/tpl_admin/adm/css/styles_admin_adm_general.css" rel="stylesheet" type="text/css" />
<LINK href="http://localhost/dev/template_eng/templates/tpl_admin/adm/css/rolodex_style.css" rel="stylesheet" type="text/css" />
<LINK href="http://localhost/dev/template_eng/templates/tpl_admin/adm/css/rolodex_print.css" rel="stylesheet" type="text/css" />
<SCRIPT src="http://localhost/dev/template_eng/common/js/functions.js" type="text/javascript" language="javascript"></SCRIPT>
<SCRIPT src="http://localhost/dev/template_eng/common/js/mootools.js" type="text/javascript" language="javascript"></SCRIPT>
<SCRIPT src="http://localhost/dev/template_eng/common/js/prototype.js" type="text/javascript" language="javascript"></SCRIPT>
<SCRIPT src="http://localhost/dev/template_eng/common/plugins/jquery/jquery.js" type="text/javascript" language="javascript"></SCRIPT>
<Script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAkis6FXftdV8MvcsjxU4NFxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxT9KLA8CW2_KbVvgT1QgENcZF5goA" type="text/javascript"></script>
<Script type="text/javascript">
Blabla blabla
now the csv file above
now ending html would show up here
How do I get it to stop exporting the pages html and just give me the file contents?
Thanks for any help