Access files outside public_html

Asked

Viewed 1,982 times

0

It is possible to consistently access files outside the public_html folder on the server to render a View?

What I need is to call files js and css and point out the images that are inside the layer View that is in app. This in turn would be at the same level of public_html, and not inside it. The public_html would contain only one file called index.php and the .htaccess. To index.php would call the Init.php in the app root that defines the routes and passes to the application’s Core to render the layout through the file Bootstrap.php

The MVC

app/
    Model/
    View/
        templates/
            css/
            img/
            js/
    Controller/
vendor/
    composer/
    Core/
pubic_html/
    - index.php
  • Ué, it’s not just using the absolute path, and giving the proper permissions. You can also get to the file using "." to access the directory "above". It would be good to inform which framework is using

  • It’s my own zend-based framework. I’ve tried accessing paths with '.. ', with the absolute path, but it’s no use. It only works when I put the files inside public_html, which is not feasible because it disrupts my MVC. I know it’s possible because I’ve seen on other sites they accessing css and js files so that it wasn’t possible to click the link to view the content. I really want to find this solution to be able to publish on my blog and post in the communities because I know it is a very common question and by my researches, never solved openly.

2 answers

1

Static files must be in the public folder or "Document root".

Otherwise, that is, the way you want to maintain the structure of files and directories, you would have to make a stream or a scheme with proxy so that static files (css, js, images) are publicly accessible.

Usually this is unnecessary and costs a lot of processing and memory. Roughly speaking, it makes no sense.

To sort out everything public, put it in the folder public.

If you have a specific reason for the images to be outside the public folder, then the conversation is different. We would be talking about xsend_file and things like.

As for CSS and JS, they can even stay out and be compiled with some template engine schema, including many platforms adopt such a practice, but this is a more complex level and I believe your system is not at this level of development due to the nature of the question.





It is worth noting that this has nothing to do with MVC:



inserir a descrição da imagem aqui

0

Why don’t you do the reverse (and more correct)?

You can create a basic structure within your public_html. Something like this:

/public_html
    /src
    /web
    .htaccess

Inside your . htacess you put to read the /web folder as if it were the root: Here you find an example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.