如何使包含路径通用? [英] How to make the include path universal?

查看:86
本文介绍了如何使包含路径通用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是php新手,有asp背景。非常感谢所有的帮助。


今天我在包含的文件中使用了include函数:


*** ************

consumer.php:<?包括inc.php ?>


inc.php:<?包括Common / functions.php ?>


functions.php:所有页面使用的常用功能

***************


如果在

<?中指定的路径,这可以正常工作包括Common / functions.php ?>

是相对于调用页面的路径的消费者.php


我希望能够指定<?包括inc.php ?>在每一页都不管

如果它嵌套在一个目录中。


在asp中我会使用这样的绝对路径:/Common/functions.php并且

会起作用。

当使用这样的路径时,PHP接近它:c:/website/site1/Common/functions.php


但是当我将页面从开发服务器转移到

实时服务器因为没有c:/ website / site1

$ b时会中断$ b我的下一个猜测是我可以用这样的变量来解决这个问题:$ docroot

.." /Common/functions.php"但是我在哪里可以在中心位置指定$ docroot?

(我会在asp的global.asa中这样做)


_SERVER ["当我请求它时,DOCUMENT_ROOT"是空白的,如果我理解

它是否正确,我可以在php.ini中设置它。问题是该值对于包装盒上的所有网站都持有




我是php的新手,所以如果我没有意义而不是让我直截了当:)


干杯,

Tom Pester

解决方案

docroot

.." /Common/functions.php"但是我在哪里指定


docroot在一个中心位置?

(我会在asp的global.asa中这样做)


_SERVER [" DOCUMENT_ROOT"]在我请求时是空白的,如果我理解

它是否正确,我可以在php.ini中设置它。问题是该值对于包装盒上的所有网站都持有




我是php的新手,所以如果我没有意义比直接让我直接:)


干杯,

Tom Pester


在文章< a1 *************************** @ news.pandora.be> ;,

tom pester <为了******************** @ pandora.be>写道:



我是php新手,有asp背景。非常感谢所有的帮助。

今天我在包含的文件中使用了include函数:

******* ********
consumer.php:<?包括inc.php ?>

inc.php:<?包括Common / functions.php ?>

functions.php:所有页面使用的常用功能
***************

如果在
<?中指定的路径很好包括Common / functions.php ?>
是相对于调用页面consumer.php的路径
我想能够指定<?包括inc.php ?>在每一页都不管它是否嵌套在一个目录中。

在asp中我会使用这样的绝对路径:/Common/functions.php它会工作。
当使用这样的路径时,PHP接近它:
c:/website/site1/Common/functions.php

但是当我从页面传输页面时会中断开发服务器到实时服务器因为没有c:/ website / site1

我的下一个猜测是我可以用这样的变量来解决这个问题:

Hi,

Im new to php and have a background in asp. All the help is very much appreciated.

today I was using the include function in a file that itself gets included :

***************
consumer.php : <? include "inc.php" ?>

inc.php : <? include "Common/functions.php" ?>

functions.php : common functions that all pages use
***************

This works fine if the path that''s specified in
<? include "Common/functions.php" ?>
is relative to the path of the calling page consumer.php

I want to be able to specify <? include "inc.php" ?> in every page no matter
if its nested in a directory or not.

In asp I would use absolute paths like this : /Common/functions.php and it
would work.
PHP comes close to it when using paths like this : c:/website/site1/Common/functions.php

But thus breaks when I transfer the pages from the development server to
the live server cause there is no c:/website/site1

My next guess was that I could solve this with a variable like this : $docroot
.. "/Common/functions.php" but where do I specify $docroot in a central location?
(I would do this in asp''s global.asa)

_SERVER["DOCUMENT_ROOT"] is blank when I request it and, if I understand
it correclty, I can set it in the php.ini . The problem is this value holds
for all the sites on the box.

I''m new to php so if I don''t make sense than pls put me straight :)

Cheers,
Tom Pester

解决方案

docroot
.. "/Common/functions.php" but where do I specify


docroot in a central location?
(I would do this in asp''s global.asa)

_SERVER["DOCUMENT_ROOT"] is blank when I request it and, if I understand
it correclty, I can set it in the php.ini . The problem is this value holds
for all the sites on the box.

I''m new to php so if I don''t make sense than pls put me straight :)

Cheers,
Tom Pester


In article <a1***************************@news.pandora.be>,
tom pester <To********************@pandora.be> wrote:

Hi,

Im new to php and have a background in asp. All the help is very much
appreciated.

today I was using the include function in a file that itself gets included :

***************
consumer.php : <? include "inc.php" ?>

inc.php : <? include "Common/functions.php" ?>

functions.php : common functions that all pages use
***************

This works fine if the path that''s specified in
<? include "Common/functions.php" ?>
is relative to the path of the calling page consumer.php

I want to be able to specify <? include "inc.php" ?> in every page no matter
if its nested in a directory or not.

In asp I would use absolute paths like this : /Common/functions.php and it
would work.
PHP comes close to it when using paths like this :
c:/website/site1/Common/functions.php

But thus breaks when I transfer the pages from the development server to
the live server cause there is no c:/website/site1

My next guess was that I could solve this with a variable like this :


这篇关于如何使包含路径通用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆