PHP路径包含文件 [英] PHP Path to Include Files
问题描述
我有一个网站用的index.php。 在index.php拥有一批包括像文件
I have a site with an index.php. The index.php has a number of include files like
<?php include_once('scripts/php/index_mainImageJoin.php');?>
我创建了一个新的文件夹断称为extrapages的根源,我将有一个有关于该网站的信息在里面的页面。我已经添加了include_once文件,如上面和更改路径和这些挂钩的罚款。
I've created a new folder off the root called 'extrapages' and I'm going to have pages in there that have information relating to the site. I've added the include_once files like above and change the path and these hook up fine.
我发现这个问题是路径中包含文件失败。例如:如果一个图像或其他包含文件中包含它从extrapages文件夹中运行时出现故障。路径问题。
The problem I'm find is paths within the include files fail. eg: if an image or another include file is within the include it fails when run from the 'extrapages' folder. Pathing issue.
有没有好的办法来处理这个? 我可以改变一个偶然的机会/路径设置站点根目录(WWW)的页面下的extrapages到一个文件夹下?
Is there a good way to deal with this? Can I change/set the path to the site root (www) for pages under 'extrapages' to one folder down by chance?
我可以将这些网页上的根源,他们会运行得很好,但我真的不希望在站点的根目录所有的混乱。
I could move these pages onto the root and they would run fine but I really don't want all the clutter on the root of the site.
任何想法和放大器; THX
Any ideas & thx
推荐答案
的关键,任何路径问题被称作绝对路径
The key to any path problem is called absolute path
-
在创建的链接的为您的网站(包括图像源),总是从
/
启动其次是完全正确的路径。它永远不会让你失望。
while creating hyperlinks for your site (including image sources), always start it from
/
followed by full correct path. And it never fail you.
同为文件系统调用:总是使用绝对路径。你的服务器通常为您提供了一个名为 $ _ SERVER ['DOCUMENT_ROOT']
包含的地步,文件系统满足web服务器非常方便的变量,指向你的网站根目录。
same for the filesystem calls: always use absolute path. Your server usually provides you with very handy variable called $_SERVER['DOCUMENT_ROOT']
contains the point where filesystem meet web-server, pointing to your web root directory.
所以,从任何地方在您的网站调用的时候,
So, when called from anywhere in your site,
include $_SERVER['DOCUMENT_ROOT'].'/scripts/php/index_mainImageJoin.php';
总是指向同一位置
will point always to the same location
这篇关于PHP路径包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!