# Images or Docs are broken

**URL:** <https://discourse.cakephp.org/t/images-or-docs-are-broken/6002>\
**Category:** Need Help\
**Created:** [April 26, 2019, 12:41pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002 "2019-04-26T12:41:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![deemi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/deemi/32/1374_2.png) [@deemi](https://discourse.cakephp.org/u/deemi)\
**Post date:** [April 26, 2019, 12:41pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/1 "2019-04-26T12:41:54Z")

</div>

Hi there, how are you.

I am working on `docs / images` uploading. For some security reasons I must upload images or docs in the folder that must be in `app` root and the folder name is `abc_docs` and in `abc_docs` folder there is a folder with the name of user\_id Like `1295`, but not in `webroot` folder. So I just create the folder `abc_docs` and upload the files or images successfully.

But now its turn for showing them …and they are broken. The message is `image can not be load`. So I just copy the link and past Like `http://localhost/myproject/app/abc_docs/1234/a1c4s5d.jpg` in address bar and enter. then cakephp me give error the you should make method in `appcontroller.php` of `abc_docs` and view … etc.

I hope you understand my question. So tell me where I am doing wrong or there is another suggestions.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 26, 2019, 3:31pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/2 "2019-04-26T15:31:53Z")

</div>

If the docs folder is not under webroot, then you will not be able to access them directly with any URL. This is presumably the entire point of the security? You will instead need to write a controller method that checks for the right access, then sends the image from the secure folder. Each of those pieces should be well covered elsewhere.

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [April 26, 2019, 3:58pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/3 "2019-04-26T15:58:21Z")

</div>

May we know what specific security reasons?  
I think you might be overthinking it because if the client loads the image, the client basically has the image.  
So I wonder what specific security reasons you had in mind…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 26, 2019, 5:11pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/4 "2019-04-26T17:11:03Z")

</div>

I was assuming it’s something like private documents where the client should definitely be able to see them (and do whatever they want with them), but nobody else should be able to access them. Like designs from an architectural firm or web developer, ticket stubs, account statements. Loads of perfectly valid possibilities, I’d say that most of my projects involve something like this.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 28, 2019, 1:00am UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/5 "2019-04-28T01:00:36Z")

</div>

First, for highly secure documents I would consider using a service.

However to save me typing, see best answer here.

[https://laracasts.com/discuss/channels/general-discussion/how-to-protect-images-and-files](https://laracasts.com/discuss/channels/general-discussion/how-to-protect-images-and-files)

Just adapt to cakephp. A unique folder name that only that user knows may be a good solution.

- not /bob
- but /b9123sdf11qa

Something like that.

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [April 28, 2019, 11:34am UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/6 "2019-04-28T11:34:17Z")

</div>

> [@jimgwhit](#):
>
> A unique folder name that only that user knows may be a good solution.

This is security by obscurity, not something I’d advice (I’ve actually had issues with this in the past).  
In the post you have send, I think the 3rd option from Snapey would be the best bet.

---

<div class="post-metadata">

**Author:** ![deemi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/deemi/32/1374_2.png) [@deemi](https://discourse.cakephp.org/u/deemi)\
**Post date:** [April 29, 2019, 9:42am UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/7 "2019-04-29T09:42:05Z")

</div>

sorry … can’t tell this

---

<div class="post-metadata">

**Author:** ![deemi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/deemi/32/1374_2.png) [@deemi](https://discourse.cakephp.org/u/deemi)\
**Post date:** [April 29, 2019, 9:43am UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/8 "2019-04-29T09:43:40Z")

</div>

yes … something like this … so is there any possibility … or i can ask another question for folder security

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [April 29, 2019, 2:12pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/9 "2019-04-29T14:12:14Z")

</div>

Well, then I think the symlinks are the best way to go honestly…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 29, 2019, 3:16pm UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/10 "2019-04-29T15:16:32Z")

</div>

As I said, write a controller method that checks for the right access, then sends the image from the secure folder. Each of those pieces should be well covered elsewhere.

---

<div class="post-metadata">

**Author:** ![deemi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/deemi/32/1374_2.png) [@deemi](https://discourse.cakephp.org/u/deemi)\
**Post date:** [April 30, 2019, 9:12am UTC](https://discourse.cakephp.org/t/images-or-docs-are-broken/6002/11 "2019-04-30T09:12:12Z")

</div>

Thanx alot @Zuluru … its done … thanx for your time
