问题
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 :)
回答1:
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');
来源:https://stackoverflow.com/questions/8634652/linux-php-require-parent-directory