Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Access images from public folder

Featured Replies

Hello I want to place images outside my web-root, i hear this improves web security.

 

One example of how these images will be used is from a Content management systems (placed on a different domain) that handles theirs websites images and places outside the web-root.. these images they have uploaded to CMS should be open for all view on there representative domains as programmed

 

But i would not like people to access cross-site information unless on the site specified , or with the necessary permissions

 

For example

 

$path = ,'/c:/your server /public_html/images/yoursite.com/'); This would be user one

 

$pathtwo = ,'/c:/your server /public_html/images/yoursitetwo.com/'); this would be user two

 

A file will be held in $path directory with a title for example of 1.jpg

 

but if someone was URL surfing right cliked the image and changed up the URL, couldnt they find other images on the server. This is the access i wish to restrict to only $path folder that is meant for that user from there domain

 

 

 

 

If you could point me in the right direction to find out how to start doing this, it would mean alot

 

Thanks in advance for your help and time

Edited by andy9l

The idea of moving files outside of the web root is mainly to make files that don't need to be run inaccessible. For example I run the core directories of Drupal and MODX outside as they leave things lying around that nobody needs to run publicly such as install scripts, configuration files and modules. If for some reason PHP stopped running on a mis-configured server you could have a field trip finding files like core/config.php etc.

 

It can also make it harder to determine what is being run and areas to exploit. I can tell eBay is running Wordpress 3.7 as like most people they have left the readme accessible. This isn't inherently secure/insecure either way but could generate less noise (random automated attacks/scans) from script kiddies targeting a specific version of something. Still, there are plenty of other ways that can be achieved but its an example of leaving things lying around that aren't really necessary.

 

In your case your directory structure approach is wrong. Instead of:

/public_html/images/yoursiteone.com/
/public_html/images/yoursitetwo.com/

You want something like:

 

/yoursiteone.com/public_html/images/
/yoursitetwo.com/public_html/images/

To keep them truly separate. Otherwise they are sharing the same public directory.

 

In most cases the images will have unique filenames so disabling directory listings should suffice. If the images aren't intended be accessible by the web whatsoever then they should be outside the web root entirely. I.e.

 

/yoursiteone.com/images/
/yoursitetwo.com/images/

Edited by Gibbs

  • Author

I know that images can pose a risk, if you add certain extensions to the end of the jpg.. of course this can be avoided with validation, but the added benefit of not having access to the file is an additional step

 

what about naming structures in something like facebook, this wouldnt stop people from domain surfing and finding others images? They limit access to others images somehow right?

i have a content management system i developed lets say its called

 

www.cms.com
my users go onto this and upload photos and other items that then display on there website.

 

1) i dont want customers of those sites

 

ie.

/yoursiteone.com

 

/yoursitetwo.com

 

people to know where the files were uploaded from, i.e www.cms.com

 

i currently have a naming structure like you spoke about, but it can be accessed.. i want to limit access

 

so for example an image on /yoursiteone.com

is actually found on www.cms.com/yoursiteone/images

 

One i dont want this, so putting above the web-root would avoid this and

 

two currently as it stands there is nothing stopping someone seeing

www.cms.com/yoursiteTWO/images images too. so i want to learn how to do this

 

saving it in the webroot isnt a problem, limiting access is.


There is a chapter in the PHP COOK BOOK named serving images securely. But it kinda confused me

 

Here is a quote from the book "you can keep all the files in one constant place, and delivery only files that pass a check inside your code"

 

how is this done?

  • Author

 

  • They suggest running images through a PHP script and using PHP "header" function to set say a PNG file and then using "readfile" to read the physical file from a location not publicly accessible E.g. above your htdocs, public_html folder etc.
  • You would thewn reference the PHP file as your image src
  • Now you are referencing a PHP script, you can perform any validation on who sees this, when the image can be displayed or even output an different image based upon the time of day

 

 

!!These were the missteps in my understanding.. thanks alot for explaining it clearly, ill try and figure it out now

 

 

Yeah thats the page i referenced

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.