Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get file outside of document root

here is my project structure:

Web root/document root:

/var/www/ all the website files in the the 'www' folder

I want to use require or include a file inside my folder OUTSIDE the web root/document root:

/var/extra-files

how can i get a file inside the extra-files folder using require or include?

require "OUTSIDE DOCUMENT ROOT/extra-files

thanks

like image 238
baileyJchoi Avatar asked Oct 18 '25 05:10

baileyJchoi


2 Answers

First make sure apache as permission to read the files on /var/extra-files, then you can use:

require "/var/extra-files/file.php";

You may want to read Difference between require, include and require_once?

like image 93
Pedro Lobito Avatar answered Oct 20 '25 19:10

Pedro Lobito


Hmm wow... no way was it that easy. I just used this:

/var/extra-files/myfile.php

and it worked.

like image 31
baileyJchoi Avatar answered Oct 20 '25 18:10

baileyJchoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!