Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux/php require parent directory

I am on Ubuntu 11.10 and installed apache server to host my local website before i host it from a company.

My website root location is "/home/a1a4a/www/"

I have a php file in /home/a1a4a/www/account/account_info.php"

That i want him to include a file in "/home/a1a4a/www/include/fg_membersite.php"

It's what i did from account_info.php

require_once('./include/fg_membersite.php');

And i got this error

Warning: require_once(./include/fg_membersite.php): failed to open stream: No such file or directory in /home/a1a4a/www/account/account_info.php on line 10 Fatal error: require_once(): Failed opening required './include/fg_membersite.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/a1a4a/www/account/account_info.php on line 10 

So what have i done wrong ? How to fix . I have full permissions ( sudo chown -R www-data ).

Thanks and Happy Holidays :)

like image 979
Shtrees Avatar asked Aug 09 '26 10:08

Shtrees


1 Answers

Always use the absolute path or you will face errors depending on the calling script.

require_once('./include/fg_membersite.php');

should actually be

require_once(dirname(dirname(__FILE__)).'/include/fg_membersite.php');
like image 164
Alec Smart Avatar answered Aug 10 '26 23:08

Alec Smart



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!