Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Storing content files
  • Hi there,

    I'm a beginner at PHP and MVC frameworks. I'm currently exploring FuelPHP to develop a simple system. The system would enable logged in users to 'read' certain media files. My question is in relation to where such files can be securely stored so that only logged in 'users' can view them.

    I have a feeling that these files should not be stored in the public folder. Where should I be storing these files or what method should I use to store these files?
  • philipptempelphilipptempel
    Accepted Answer
    There's two ways you can solve the issue:

    1) As you have mentioned correctly, store your files outside of public/ and create a controller that will provide the files. This controller can then check for the specific permission and deny access if not allowed.

    2) Store the files in a blob-column inside the database. This is basically no different to above idea, except that your files are not stored on the disk and cannot even be accessed over the shell - at least not accessed directly.

    In either way you need to be careful of the mimetypes to tell the browser what data it is processing - an HTML page has a different mimetype compared to an image. Not taking care of this may lead to issues with viewing/downloading files.
    The second solution comes at a price: Your database can grow rapidly in size unless you have a very small limit on the file upload size. This will cause your database to slow down over time and therefore your app, as well. Furthermore it requires at least one additional call to the database. Which, for one user, isn't much, but depending on your app's traffic it can cause quite a load on your system.

    Thus all said, the universal answer applies here as well:
      It depends
  • Just some clarification, for the first method, creating a folder in the root directory of the project is what is meant right?
  • Yeah. That is correct.

    Or technically you can create a folder anywhere but within DOCROOT/public. Additionally, that folder must be accessible by the server - therefore, the easiest would be to create a folder "uploads" inside the "fuel/app/" directory (that's what I do in case I want non-public file uploads)
  • Okay, Thanks :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion