保证include文件中的路径总是可用
时间:2007-02-17 来源:PHP爱好者
这个是让人头疼的问题,我的解决办法是:使用绝对路径,并用 $MAIN_PATH 和 $Con_MAINPATH 两个变量保持其可移植性。
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
比如:
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
<?
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$Con_MAINPATH="http://lastleaf.51.net/cgi-bin";
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$MAINPATH="/home/myweb/cgi-bin"
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
#include "$MAINPATH/php/showphp.php"; //调用别的文件。
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
//如果showphp.php中还要调用别的文件,
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
//则写成 "url=$Con_MAINPATH/php/title.gif" 。
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
?>
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
注意区分url和文件路径,比如:
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$fp=fopen("$MAINPATH/files/a.htm","r");
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
echo "<a herf=$Con_MAINPATH/files/a.htm>Click here</a>";
非常全面的一个php技术网站,php爱好者站 http://www.phpfans.net 有相当丰富的文章和源代码.
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
比如:
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
<?
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$Con_MAINPATH="http://lastleaf.51.net/cgi-bin";
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$MAINPATH="/home/myweb/cgi-bin"
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
#include "$MAINPATH/php/showphp.php"; //调用别的文件。
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
//如果showphp.php中还要调用别的文件,
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
//则写成 "url=$Con_MAINPATH/php/title.gif" 。
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
?>
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
注意区分url和文件路径,比如:
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
$fp=fopen("$MAINPATH/files/a.htm","r");
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
chinaitpower.comwKJZ6ih4oCgsPjQ3tNJSfl3Qh
echo "<a herf=$Con_MAINPATH/files/a.htm>Click here</a>";
非常全面的一个php技术网站,php爱好者站 http://www.phpfans.net 有相当丰富的文章和源代码.
相关阅读 更多 +