Hi Robert,

This line

header("Content-Disposition: attachment; filename=customers.xls");

forces IE to save. If you change attachment to inline it will open the
Excel in the plug-in imbeded in the browser.

- Frank

> I have the script below from another source, and it works prefectly in
> Mozilla, however IE keeps wanting to save the PHP page and then barfs.
> Any ways to fix and make it work for both?
> 
> TIA!
> Robert
> 
> <CODE>
> 
> <?php
> //Written by Dan Zarrella. Some additional tweaks provided by JP
> Honeywell
> //pear excel package has support for fonts and formulas etc.. more
> complicated
> //this is good for quick table dumps (deliverables)
> 
> //Includes Snipped for posting
> //DB Query tweaked for usage
> $result = mysql_query("select * from customers where cust_salesmen =
> $user_id");
> $count = mysql_num_fields($result);
> 
> for ($i = 0; $i < $count; $i++){
>     $header .= mysql_field_name($result, $i)."\t";
> }
> 
> while($row = mysql_fetch_row($result)){
>   $line = '';
>   foreach($row as $value){
>     if(!isset($value) || $value == ""){
>       $value = "\t";
>     }else{
> # important to escape any quotes to preserve them in the data.
>       $value = str_replace('"', '""', $value);
> # needed to encapsulate data in quotes because some data might be multi
> line.
> # the good news is that numbers remain numbers in Excel even though
> quoted.
>       $value = '"' . $value . '"' . "\t";
>     }
>     $line .= $value;
>   }
>   $data .= trim($line)."\n";
> }
> # this line is needed because returns embedded in the data have "\r"
> # and this looks like a "box character" in Excel
>   $data = str_replace("\r", "", $data);
> 
> 
> # Nice to let someone know that the search came up empty.
> # Otherwise only the column name headers will be output to Excel.
> if ($data == "") {
>   $data = "\nno matching records found\n";
> }
> 
> # This line will stream the file to the user rather than spray it
across
> the screen
> header("Content-type: application/octet-stream");
> 
> # replace excelfile.xls with whatever you want the filename to default
> to
> header("Content-Disposition: attachment; filename=customers.xls");
> header("Pragma: no-cache");
> header("Expires: 0");
> 
> echo $header."\n".$data;
> ?> 
> <! END Code>
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to