I have a folder outside of webroot with important images. I am using $this->response->file in my controller successfully when I just pass in the file name. However I need to pass in part of the path as it is made up of id's. I know I can not pass / as it is so I use rawurlencode() which does change it to %2F. The problem now is that the controller does not get called anymore as the browser still reads it as a / and I get
-- The url
http://localhost:8888/btstadmin/books/sendFile/38%2Fbackgrounds%2Forchard-left.png
Not Found
The requested URL /btstadmin/books/sendFile/38/backgrounds/orchard-left.png was not found on this server.
The view code
<?php echo (isset($book['Book']['admin_image']) && !empty($book['Book']['admin_image']) ? '<img src="books/sendFile/'.rawurlencode("38/backgrounds/orchard-left.png").'" width="100%" alt="aswq" />' : '') ?>
Which gives me
<img src="books/sendFile/38%2Fbackgrounds%2Forchard-left.png" width="100%" alt="aswq">
The controller which gets called and works if it is just the file name:
public function sendFile($file) {
$file = rawurldecode($file);
$path = ROOT.DS.'bookUploads'.DS.'Users'.DS.'ingemit/Books/'.$file;
$this->response->file($path);
return $this->response;
}
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment