I grabbed this bit of code from the PHP.net readfile page:
<?php
// Action controller
public function someAction() {
$response = $this->_response;
// Disable view and layout rendering
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
// Process the file
$file = 'whatever.zip';
$bits = @file_get_contents($file);
if(strlen($bits) == 0) {
$response->setBody('Sorry, we could not find requested download file.');
}
else {
$response->setHeader('Content-type', 'application/octet-stream', true);
$response->setBody($bits);
}
}
?>
It works great with most files but when I test it on a file with spaces in the filename, it says it can't find the requested file. Any suggestions, or is there a better way to do a readfile in Zend Framework where the filename can have spaces in it?