Hi all,
I’m using Cake 2.6.7 and trying to use CakeResponse::file() to to send files to the browser from a directory outside of web root. I have no problems when sending jpgs for inline display or download, and no problems with pdfs when downloading, but I get an error when I request the same pdf for inline display with the following error,
The requested file C:\Users\ted\Programming\UwAmp\www\docsafe\app\C:\Users\ted\Programming\UwAmp\www\docsafe\app\Uploads/000/000/000/2\test was not found or not readable
In summary I have two files in an Uploads sub-directory under the APP directory callled test.jpg and test.pdf
Here is the code in my Documents Controller
public function download($id = null, $file = null, $method = null) {
// $id = document_id
// $file = filename (inc extension)
// $method = download or inline
$this->autoRender = false;
$file_path = $this->__getFileDirectory($id); //gets sub-directory path based on record id
if($method == 'd')
{
$this->response->file(
APP .'Uploads' . DS . $file_path . DS . $file,
array(
'download' => true,
'name' => $file
)
);
} else {
$this->response->file(
APP . 'Uploads' . DS . $file_path . DS . $file
);
}
}
When I call
docsafe.dev/documents/download/2/test.jpg/d I get the jpg downloaded
docsafe.dev/documents/download/2/test.jpg I get the jpg viewable inline
docsafe.dev/documents/download/2/test.pdf/d I get the pdf downloaded
However when I call
docsafe.dev/documents/download/2/test.pdf I get an error?
I know that file and path are correct because I can download the pdf, but I’ve noticed the error given (above) somehow concatenates the path together twice. I don’t under why it works for jpgs but not for pdfs, even though I can download the pdf okay?
Am I missing something obvious?
Thanks