title: PHP store photos in a folder that is not public
body: <p>I would like to create a photo sharing php web site, I am pretty new to you PHP I am used to Java based servers.</p>
  
  <p>I want to provide a form to upload an image. I want to be able to upload many hundreds of images, so it is probably better to store the image in a local file folder, and store a pointer to that file in the database. The reason is because the MySQL database is limited but the disk space is not.</p>
  
  <p>The person who uploaded the image can then share this photo with certain other users, so I will have a table to maintain the permissions for the image.</p>
  
  <p>I do not want this photo to download using a direct URL - a URL should provide the ID for the image as a query parameter, and the server will respond with that image, but it will only work if that user has permission to the file. I know how to do this, by creating a php that will read the file and output to the response.</p>
  
  <p>If I store the photo on the disk inside of some folder somewhere, how do I make sure the photo cannot be hit using the direct URL like <code>/path/to/photo.png</code>?</p>