Quantcast
Viewing all articles
Browse latest Browse all 21

Php file download is putting two lines with a line feed at the top

I have a script that receives a parameter then downloads a file to the clients browser. The file is not located in a folder accessible under the docent root

When my script executes pdf's work fine but word docents do not.

I have examined the files with notepad++ with show symbols on and both the pdf's and docs have two lines at the top containing a LF according to notepad++ (looks like adobe reader is more forgiving).

I have checked everything I can think of. I have tried passing the file to trim befor outputting, checked there is no whitespace before opening php tags, tried creating a file as an array looping every element and not echoing the forst two if they contain "\n",

Could this be apache set up issues?

Example Script:

<?php
class TrainingDatabase_IndexController extends Zend_Controller_Action
{

public function downloadAction()
{
            $this->view->layout()->disableLayout();
            $this->_helper->viewRenderer->setNoRender(true);

            // Get filepath and decode it from get param
            $filepath = urldecode( $this->_request->getParam('directory') );

            // Return the basename for save as filename
            $filename = basename($filepath);


            // Set the headers
            header('Content-Disposition: attachment; filename="' . $filename . '"' );
            header('Content-Description: File Transfer');
            header('Content-Transfer-Encoding: binary');
            header('Content-Type: application/octet-stream');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Expires: 0');
            header('Content-Length: '.filesize($filepath));

            // Make sure nothing is left in the browser
            ob_clean();
            flush();

            // Output the file
            readfile($filepath);
   }
}

Viewing all articles
Browse latest Browse all 21

Trending Articles