Linux/php require parent directory

五迷三道 提交于 2019-12-12 19:20:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!