I'm working in CakePHP 3.4.
I have an image outside img
directory, in files
directory under webroot
I have a files
directory inside webroot
along with css
, img
, js
.
I tried using it like
$this->Html->image(WWW_ROOT . 'files' . DS . 'myimage.jpg')
which is creating path as
/var/www/html/myproject/webroot/files/myimage.jpg
But this is not showing image. Copying and pasting path in another tab is loading image perfectly. Also, moving image file to img
directory and using $this->Html->image('myimage.jpg')
is working fine.
Why it is not working ? Also, It is easy to build url for directories css
, img
and js
like
// Outputs http://example.com/img/icon.png
$this->Url->image('icon.png', true);
OR
// Outputs /img/icon.png
$this->Url->image('icon.png');
which will result as
http://example.com/img/icon.png
I want to build url for files
directory like
http://example.com/files/myfile.jpg
OR
// /files/myfile.jpg
How to build url for directories other than img
, css
and js
.?