Okay, I got it thanks to some guidance from _psychic_  thank you!

So, the problem here was that the headers were all wrong.

They went from:

                header("Content-type: application/vnd.ms-excel");
                header("Content-Disposition: attachment; filename=
$file_name");
                header("Pragma: no-cache");
                header("Expires: 0");

To:

                $mm_type="application/octet-stream";

                header("Cache-Control: public, must-revalidate");
                header("Pragma: hack");
                header("Content-Type: " . $mm_type);
                //header("Content-Length: " .(string)(filesize($fullpath)) );
                //header('Content-Disposition: attachment; filename="'.
$filename.'"');
                header("Content-Transfer-Encoding: binary\n");

                //header("Content-type: application/vnd.ms-excel");
                header("Content-Disposition: attachment; filename=$file_name");
                // header("Pragma: no-cache");
                header("Expires: 0");

I think what did it was the "application.octet-stream" and the
"Content-Transfer-Encoding: binary\n"

Thanks again _psychic_

Here was where I found these headers:

http://us2.php.net/header

A post by : blinki bill

On May 8, 12:14 pm, "Christopher E. Franklin, Sr."
<[EMAIL PROTECTED]> wrote:
> Hello wonderful group!
>
> I have written some code that in essence, takes a date range and
> serves up two different formats depending what button you click.
>
> Firstly, is the "View" button.  So, for example, I select a date range
> and click view, I get a table on the same page with the information I
> need.  This works fine in IE7 and Firefox.
>
> Secondly, I have another button called "Export".  Basically, it is the
> same form with the date ranges except, when I click the button, it
> calls a different function in my controller.  The controller gets the
> data from the model and packages it via a component as comma separated
> values (CSV).  It then just echos out the PHP headers and the CSV
> data.
>
> My problem is, it works fine in Firefox.  When I click export, the
> date range is submitted, and I get a download window for the xls
> file.  But, when I do the same thing in IE7 and IE6, I get an error
> stating that:
>
> "Internet Explorer cannot download renewals_certificate_export from
> subdomain.domain.com"
>
> "Internet Explorer was not able to open this Internet site. The
> requested site is either unavailable or cannot be found. Please try
> again later."
>
> So, while this error message is being displayed, I see the download
> box in the background, like it is ready to download.  So, that tells
> me that the headers for php are correct but, I cannot figure out why
> IE7 has a problem downloading variable data on the fly.
>
> I have tried changing the headers to something else to no avail.  I
> have tried making the URL different by including the full URL, with an
> ending slash (/) and also by including a file name on the end and
> accepting it in my controller function (/text.xls).
>
> I am at a loss here.  So, I know it's a problem with IE7, not CakePHP
> or with the PHP headers.  Just wondering if anyone has had a similar
> problem?  If so, were you able to resolve the issue?
>
> Here is my code:
>
> Controller
> -------------
>
>         function renewals_certificate_export($name = null) {
>                 Configure::write('debug', 0);
>                 if(!empty($this->data)) {
>                         $from = date('Y-m-d', strtotime($this->data['Report']
> ['from_month']."/".$this->data['Report']['from_day']."/".$this->data['Report']['from_year']))."
>  00:00:00";
>
>                         $to = date('Y-m-d', 
> strtotime($this->data['Report']['to_month']."/".
> $this->data['Report']['to_day']."/".$this->data['Report']
> ['to_year']))." 23:59:59";
>                         $not = '';
>                         if($this->data['Report']['stager'] == 0) {
>                                 $not .= "AND type != 'Stager' ";
>                         }
>                         if($this->data['Report']['master'] == 0) {
>                                 $not .= "AND type != 'Master' ";
>                         }
>                         if($this->data['Report']['realtor'] == 0) {
>                                 $not .= "AND type != 'Realtor' ";
>                         }
>                         if($this->data['Report']['iahsp'] == 0) {
>                                 $not .= "AND type != 'Iahsp'";
>                         }
>                         $results = $this->Report->findAll("date >= '$from' 
> AND date <=
> '$to' $not");
>                         foreach($results as $key => $value) {
>                                 $user = 
> $this->Asp->findByUid($value['Report']['uid']);
>                                 $results[$key]['Report']['first_name'] = 
> $user['Asp']['fname'];
>                                 $results[$key]['Report']['last_name'] = 
> $user['Asp']['lname'];
>                                 $results[$key]['Report']['email'] = 
> $user['Asp']['email'];
>                                 $results[$key]['Report']['expiration_date'] = 
> $user['Asp']
> ['anniversary'];
>                         }
>                         $this->Excel->addRow(array("ID", "First Name", "Last 
> Name", "Type",
> "Email", "Expiration Date"));
>                         foreach($results as $key => $value) {
>                                 
> $this->Excel->addRow(array($value['Report']['uid'],
> $value['Report']['first_name'], $value['Report']['last_name'],
> $value['Report']['type'], $value['Report']['email'], date('Y-m-d',
> strtotime($value['Report']['expiration_date']))));
>                         }
>                         $this->Excel->download(date('Y-m-d', 
> strtotime($this->data['Report']
> ['from_month']."/".$this->data['Report']['from_day']."/".$this->data['Report']['from_year']))."_".date('Y-m-d',
>  strtotime($this-
> >data['Report']['to_month']."/".$this->data['Report']['to_day']."/".
>
> $this->data['Report']['to_year'])).".xls");
>                 }
>         }
>
> Excel Component
> --------------------------
>
> class ExcelComponent extends Object {
>         var $lines;
>
>         function addRow($data) {
>                 if(is_array($data)) {
>                         foreach($data as $key => $value) {
>                                 $this->lines .= trim($value)."\t";
>                         }
>                         $this->lines = str_replace("\r","",$this->lines);
>                         $this->lines .= "\n";
>                 } else {
>                         trigger_error("Expecting an array to add for a row to 
> the excel
> sheet");
>                         exit;
>                 }
>         }
>
>         function download($file_name = null) {
>                 if($file_name == null) {
>                         $file_name = "export.xls";
>                 }
>                 header("Content-type: application/vnd.ms-excel");
>                 header("Content-Disposition: attachment; 
> filename=$file_name");
>                 header("Pragma: no-cache");
>                 header("Expires: 0");
>                 print $this->lines;
>                 exit;
>         }
>
> }
>
> View for initial page (NOT THE VIEW FOR THE EXPORT FUNCTION)
> ---------------------------------------------------------------------------­-------------------------
>
> <style type="text/css">
> #calendarcontainer {padding:10px;}
> #calendarmenufrom, #calendarmenuto {position: absolute;}
> #calendarpickerfrom button, #calendarpickerto button {
>     background: url(/js/yui/build/button/assets/skins/sam/
> calendar_icon.gif) center center no-repeat;
>     text-align: left;
>     text-indent: -10em;
>     overflow: hidden;
>     *margin-left: 10em; /* For IE */
>     *padding: 0 3em;    /* For IE */
>     white-space: nowrap;}
>
> #ReportFromMonth, #ReportFromDay, #ReportToDay, #ReportToMonth {width:
> 2em;}
> #ReportFromYear, #ReportToYear {width: 3em;}
> #datefields {
>         border: solid 1px #666;
>         padding: .5em;}
>
> #calendarpickerfrom, #calendarpickerto  {vertical-align: baseline;}
> </style>
> <h1 class="title">Renewal Certificate Report Generator</h1>
> <p>Select the date range which you wish to view.</p>
> <?php echo $form->create('Report', array('action' =>
> 'renewals_certificate')); ?>
> <fieldset>
>         <legend>Search Criteria</legend>
>         <p>
>                 <?php echo $form->checkbox('stager', array('checked' => 
> true)); ?>
>                 <?php echo $form->checkbox('master', array('checked' => 
> true)); ?>
>                 <?php echo $form->checkbox('realtor', array('checked' => 
> true)); ?>
>                 <?php echo $form->checkbox('iahsp', array('checked' => 
> true)); ?>
>         </p>
>         <script type="text/javascript">
>                 // Checkbox Buttons
>                 var oReportStager = new YAHOO.widget.Button("ReportStager",
> { label:"Stager" });
>                 var oReportMaster = new YAHOO.widget.Button("ReportMaster",
> { label:"Master" });
>                 var oReportRealtor = new YAHOO.widget.Button("ReportRealtor",
> { label:"Realtor" });
>                 var oReportIahsp = new YAHOO.widget.Button("ReportIahsp",
> { label:"Iahsp" });
>
>                 // Calendar Functions
>         YAHOO.util.Event.onDOMReady(function () {
>                         function onCalendarFromButtonClick() {
>                 oCalendarFromMenu.setBody("&#32;");
>                     oCalendarFromMenu.body.id = "calendarcontainer";
>                     oCalendarFromMenu.render(this.get("container"));
>                     oCalendarFromMenu.align();
>                     var oCalendarFrom = new
> YAHOO.widget.Calendar("buttoncalendar", oCalendarFromMenu.body.id);
>                     oCalendarFrom.render();
>
>                     oCalendarFrom.changePageEvent.subscribe(function () {
>                         window.setTimeout(function () {
>                             oCalendarFromMenu.show();
>                             }, 0);
>
>                     });
>
>                     oCalendarFrom.selectEvent.subscribe(function (p_sType,
> p_aArgs) {
>                         var aDate;
>                         if (p_aArgs) {
>                             aDate = p_aArgs[0][0];
>                             YAHOO.util.Dom.get("ReportFromMonth").value =
> aDate[1];
>                             YAHOO.util.Dom.get("ReportFromDay").value =
> aDate[2];
>                             YAHOO.util.Dom.get("ReportFromYear").value =
> aDate[0];
>                         }
>                         oCalendarFromMenu.hide();
>                 });
>                 this.unsubscribe("click", onCalendarFromButtonClick);
>                 }
>
>                 function onCalendarToButtonClick() {
>                 oCalendarToMenu.setBody("&#32;");
>                     oCalendarToMenu.body.id = "calendarcontainer";
>                     oCalendarToMenu.render(this.get("container"));
>                     oCalendarToMenu.align();
>                     var oCalendarTo = new
> YAHOO.widget.Calendar("buttoncalendar", oCalendarToMenu.body.id);
>                     oCalendarTo.render();
>
>                     oCalendarTo.changePageEvent.subscribe(function () {
>                         window.setTimeout(function () {
>                             oCalendarToMenu.show();
>                             }, 0);
>
>                     });
>
>                     oCalendarTo.selectEvent.subscribe(function (p_sType,
> p_aArgs) {
>                         var aDate;
>                         if (p_aArgs) {
>                             aDate = p_aArgs[0][0];
>                             YAHOO.util.Dom.get("ReportToMonth").value =
> aDate[1];
>                             YAHOO.util.Dom.get("ReportToDay").value =
> aDate[2];
>                             YAHOO.util.Dom.get("ReportToYear").value =
> aDate[0];
>                         }
>                         oCalendarToMenu.hide();
>                 });
>                 this.unsubscribe("click", onCalendarToButtonClick);
>                 }
>
>                 var oCalendarFromMenu = new
> YAHOO.widget.Overlay("calendarmenufrom");
>                 var oCalendarToMenu = new
> YAHOO.widget.Overlay("calendarmenuto");
>
>                 var oCalendarFromButton = new YAHOO.widget.Button({
>                                                     type: "menu",
>                                                     id: "calendarpickerfrom",
>                                                     label: "From",
>                                                     menu: oCalendarFromMenu,
>                                                     container:
> "date_fields_from" });
>                 var oCalendarToButton = new YAHOO.widget.Button({
>                                                     type: "menu",
>                                                     id: "calendarpickerto",
>                                                     label: "To",
>                                                     menu: oCalendarToMenu,
>                                                     container:
> "date_fields_to" });
>
>                 oCalendarFromButton.on("click", onCalendarFromButtonClick);
>                 oCalendarToButton.on("click", onCalendarToButtonClick);
>             });
>         </script>
>         <fieldset>
>                 <legend>From</legend>
>                 <p id="date_fields_from">
>                         <label for="ReportFromMonth">Month: </label> <?php 
> echo $form->input('from_month', array('label' => false, 'div' => false,
>
> 'maxlength' => 4)); ?>
>                 <label for="ReportFromDay">Day:</label> <?php echo 
> $form->input('from_day', array('label' => false, 'div' => false, 'maxlength'
>
> => 4)); ?>
>                 <label for="ReportFromYear">Year: </label> <?php echo 
> $form->input('from_year', array('label' => false, 'div' => false,
>
> 'maxlength' => 4)); ?>
>             </p>
>         </fieldset>
>     <fieldset>
>         <legend>To</legend>
>             <p id="date_fields_to">
>                 <label for="ReportToMonth">Month: </label> <?php echo 
> $form->input('to_month', array('label' => false, 'div' => false, 'maxlength'
>
> => 4)); ?>
>                 <label for="ReportToDay">Day:</label> <?php echo 
> $form->input('to_day', array('label' => false, 'div' => false, 'maxlength'
>
> => 4)); ?>
>                 <label for="ReportToYear">Year: </label> <?php echo 
> $form->input('to_year', array('label' => false, 'div' => false, 'maxlength'
>
> => 4)); ?>
>             </p>
>     </fieldset>
> </fieldset>
> <p><input type="submit" value="Export" onclick="$
> ('ReportRenewalsCertificateForm').action = '/reports/
> renewals_certificate_export/';" /><input type="submit" value="View"
> onclick="$('ReportRenewalsCertificateForm').action = '/reports/
> renewals_certificate';" /></p>
> <?php
>         echo $form->end();
>         if(isset($results) && !empty($results)) {
> ?>
> <h2>Renewal Information</h2>
> <?php
>         $yahoo_data = "var renewal = { renewals: [ ";
>         foreach($results as $result) {
>                 $yahoo_data .= "{id:".intval($result['Report']['uid']).", " .
>                                        
> "name:'".$result['Report']['first_name']."
> ".substr($result['Report']['last_name'], 0, 10)."', " .
>                                        "type:'".$result['Report']['type']."', 
> " .
>                                        
> "length:".$result['Report']['length'].", " .
>                                        
> "expiration:'".$result['Report']['expiration']."', " .
>                                        
> "email:'".$result['Report']['email']."'}, ";
>         }
>         $yahoo_data = rtrim($yahoo_data, ', ');
>         $yahoo_data .= " ] };\n";
> ?>
> <div id="renewal_grid"></div>
> <script type="text/javascript">
> <?php echo $yahoo_data; ?>
> YAHOO.util.Event.addListener(window, "load", function() {
>         var formatUrl = function(elCell, oRecord, oColumn, sData) {
>                                 elCell.innerHTML = "<a href='/aspinfo/" +
> oRecord.getData("id") + "' target='_blank'>" + sData + "</a>";
>                                 };
>     YAHOO.example.Basic = new function() {
>         var myColumnDefs = [
>             {key:"id", formatter:YAHOO.widget.DataTable.formatNumber,
> sortable:true, resizeable:true},
>             {key:"name", formatter:formatUrl, sortable:true,
> resizeable:true},
>             {key:"type", sortable:true, resizeable:true},
>             {key:"length", sortable:true, resizeable:true},
>             {key:"date", sortable:true, sortOptions:
> {defaultDir:YAHOO.widget.DataTable.CLASS_ASC},resizeable:true},
>             {key:"expiration", sortable:true, sortOptions:
> {defaultDir:YAHOO.widget.DataTable.CLASS_ASC},resizeable:true},
>             {key:"email", sortable:true,resizeable:true}
>         ];
>
>         this.myDataSource = new
> YAHOO.util.DataSource(renewal.renewals);
>         this.myDataSource.responseType =
> YAHOO.util.DataSource.TYPE_JSARRAY;
>         this.myDataSource.responseSchema = {
>             fields: ["id","name","type","length","expiration","email"]
>         };
>
>         this.myDataTable = new YAHOO.widget.DataTable("renewal_grid",
>                 myColumnDefs, this.myDataSource,
> {caption:"Renewals"});
>     };});
>
> </script>
> <?php}
>
> ?>
>
> Any help or suggestions would be greatly appreciated.  In the mean
> time, I am going to try and make the xls file and actually write it to
> disk and serve it up that way to see if it works.  Will post my
> findings here.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to