Jump to content

Recommended Posts

One more question for you all:

 

We just installed a new Linux Ubuntu V 11.04 server with LAMP (Apache2, PHP 5.3.x, MySQL 5.1.4, etc...) all out of the box stuff.

 

I developed (locally) and app where I am exporting some data from MySQL, putting it into a spreadsheet and then sending the Excel file to the client. This all worked fine in my dev setup. BUT... (you know whats coming next) after deploying the app to the new Web Server, when I attempt to export the data, I am successfully creating the Excel file but rather than opening the download dialogue box, the data is being read and sent to the browser window as text!

 

As I mentioned before, this is a new web server, so there may be something missing on the Apache2 setup, or my code may just be crap. Either way, my head hurts and cannot find out what is happening.

 

Here is my header type configuration:

<?php
function save($filename, $download=false, $download_filename="")
    {
        if (!$download)
        {
            return $this->domXML->save($filename);
        }
        elseif ($this->domXML->save($filename))
        {
            $realFileInfo = $_SERVER['DOCUMENT_ROOT'].'/truck/admin/export/'.$download_filename; 
            $FileInfo = pathinfo($filename);
            ob_end_clean();
            // fix for IE catching or PHP bug issue 
            header("Pragma: public"); 
            header("Expires: 0"); // set expiration time 
            header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); 
            header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
            header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
            header ("Pragma: no-cache"); 
            //header("Cache-Control: must-revalidate, post-check=0, pre-check=0");  
            
            // browser must download file from server instead of cache 
            // force download dialog 
            header("Content-Type: application/force-download"); 
            header("Content-Type: application/octet-stream");
            header('Content-Type: application/vnd.ms-excel;');                 // This should work for IE & Opera  
            header("Content-type: application/x-msexcel");
            header("Content-Type: application/download"); 
            
            // use the Content-Disposition header to supply a recommended filename and  
            // force the browser to display the save dialog.
            if ($download_filename == "")$download_filename = "download.xls";
            //header("Content-Disposition: attachment; filename=".$download_filename.";"); 
            header("Content-Disposition: attachment; filename=".$realFileInfo.";"); 
            header("Content-Transfer-Encoding: binary");
            //header("Content-Length: ".filesize($filename)); 
            header("Content-Length: ".filesize($realFileInfo)); 
            
            //@readfile($filename);
            @readfile($realFileInfo);
            return true;
        }
        return false;
    }
?>

 

Can you see anything wrong?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/236659-need-help-with-download-header/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.