Friday 15 August 2014

php - Run an Html file in Apache Server from outside web root -



php - Run an Html file in Apache Server from outside web root -

i have folder contain html, css, js, image files across various folders. security reasons want place outside web root.

i have come across solution using file_get_contents function of php.

but there problem hyper-linking nowadays in page. example, link javascript file in page:

<script src="lms/apiconstants.js" type="text/javascript"></script>

searches file in http://localhost/lms/apiconstants.js , returns error of

failed load resource: server responded status of 404 (not found) http://localhost/lms/apiconstants.js

i aware of using .htaccess file hiding folders web root. looking other insightful solution.

finally solved this.. might helpful others.

steps followed:

use separate file reading outside web root (say filereader.php). call file url encoding local file path. http://localhost.ca/lms/filereader.php/path/to/local/file.html parse url path - /path/to/local/file.html apply php's readfile() function read obtained path.

doing this, hyperlinks in file.html gets loaded next path.

http://localhost.ca/lms/filereader.php/path/to/local/

the mime-type each file has defined. proper http response code thrown using php's http_response_code() when file not found.

note: might need enable acceptpathinfo in apache configuration.

php apache

No comments:

Post a Comment