CakeResponse::file() and sending pdfs

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

I’ve looked into this further and now know why it is failing, although I don’t know if this is through accident or design?

I have added the following line at the start of the function download

echo pr($this->request);

This has revealed that CakePHP changes the parameters.

When I pass a a url with a jpg to be returned, I get the following parameters at the point that the function is called

[params] => Array
(
[plugin] =>
[controller] => documents
[action] => download
[named] => Array
(
)

    [pass] => Array
        (
            [0] => 2
            [1] => test.jpg

However when I pass a pdf CakePHP strips off the dot extension and places it into its own variable,

[params] => Array
(
[plugin] =>
[controller] => documents
[action] => download
[named] => Array
(
)

    [pass] => Array
        (
            [0] => 2
            [1] => test
        )

    [ext] => pdf

This action later causes the confirmation of the existence of the file to fail as its now looking for a file called test and not test.pdf.

Why does CakePHP do this, is it intentional or unintentional?

BUMP!

The greatest Cake minds in the world…