Home >php教程 >php手册 >保证include文件中的路径总是可用

保证include文件中的路径总是可用

WBOY
WBOYOriginal
2016-06-13 10:23:261131browse

这个是让人头疼的问题,我的解决办法是:使用绝对路径,并用 $MAIN_PATH 和 $Con_MAINPATH 两个变量保持其可移植性。
比如:


$Con_MAINPATH="http://lastleaf.51.net/cgi-bin";

$MAINPATH="/home/myweb/cgi-bin"

#include "$MAINPATH/php/showphp.php"; //调用别的文件。

//如果showphp.php中还要调用别的文件,
//则写成 "url=$Con_MAINPATH/php/title.gif" 。

?>

注意区分url和文件路径,比如:

$fp=fopen("$MAINPATH/files/a.htm","r");

echo "Click here";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn