PHP.net の readfile ページからこのコードを入手しました。
<?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);
}
}
?>
ほとんどのファイルでうまく機能しますが、ファイル名にスペースが含まれるファイルでテストすると、要求されたファイルが見つからないと表示されます。任意の提案、またはファイル名にスペースを含めることができる Zend Framework で readfile を実行するより良い方法はありますか?