Reputation: 806
I have a folder which contain HTML, CSS, JS, image files across various folders. For security reasons I want to place it outside the web root.
I have come across a solution using file_get_contents
function of PHP.
But then there is a problem with hyper-linking present in the page. For example, the link to the javascript file in the page:
<script src="lms/APIConstants.js" type="text/javascript"></script>
searches for the file in http://localhost/lms/APIConstants.js
and returns an error of
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/lms/APIConstants.js
I am aware of using .htaccess file for hiding some folders from the web root. I am looking for some other insightful solution.
Upvotes: 0
Views: 849
Reputation: 806
Finally solved this.. Might be helpful for others.
Steps that were followed:
/path/to/local/file.html
readfile()
function to read from the obtained path.Doing this, all the hyperlinks in file.html
gets loaded from the following path.
The mime-type for each file has to be defined. Also a proper http response code is to be thrown using PHP's http_response_code()
when a file is not found.
Note: You might need to enable AcceptPathInfo
in the Apache configuration.
Upvotes: 1
Reputation: 1
when you include a file then code/script runs according to new path on which it is being included.
It finds the APIConstants.js file into the folder Ims which is in root directory. but actually it is outside the root directory.
So give the path like this.. If Ims folder is one step down to the root directory.
src="../lms/APIConstants.js"
Upvotes: 0