相对路径/绝对路径 [英] relative path / absolute path

查看:160
本文介绍了相对路径/绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候:


解决文档中路径的最佳方法是什么?无论打开它的路径是什么?
路径?例如:我有x.php,它包含< img

src =" images ...">,(其中包括像php代码),它解决了这个问题。 />
在/下打开时正确的图像路径但是当x.php被读入文件时

下/ dir图像不再解析,原因很明显。使用绝对的

路径,这不是一个问题,但它是相对路径。虽然我可以想到一两块钱,我觉得有一个更优雅的解决方案。

提前谢谢。


-


问候,


Jerry M. Gartner

Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images...">, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn''t an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.

--

Regards,

Jerry M. Gartner

推荐答案

Jerry M. Gartner写道:
Jerry M. Gartner wrote:
问候:

解决文档中路径的最佳方法是什么,无论路径是什么打开下?例如:我有x.php,它包含< img
src =" images ...">,(其中包括像php代码),它可以解析
正确的图像在/下打开时的路径但是当x.php被读入文件时
在/ dir下图像不再解析,原因很明显。凭借绝对的路径,这不是一个问题,而是相对路径。虽然我可以想到一两个,但我认为有更优雅的解决方案。
提前致谢。
Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images...">, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn''t an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.



如果我理解正确的话,这实际上是一个Web服务器问题,并且是由Apache中的别名功能处理的(其他服务器可能称之为
其他服务器)。此功能允许您设置路径前缀 - 例如,

/ images - 并将所有对图像的引用解析到同一个地方。


所以在您的代码< img src =" /images/foo.gif">并且无论在何处引用

,它都会在/my_web/images/foo.gif中解析为




别名也可用于css,javascript或任何其他通常

共享代码元素。


希望这会有所帮助。

-david-


If I understand you correctly, this is really a web server issue and is
handled by the ''Alias'' function in Apache (other servers may call it
something else). This function allows you to set a path prefix - say,
/images - and have all references to an image resolve to the same place.

So in your code you would have <img src="/images/foo.gif"> and it would
resolve to /my_web/images/foo.gif regardless of where it was referenced
in your web document tree.

Aliases may also be used for css, javascript or any other commonly
shared code elements.

Hope this helps.
-david-


Jerry M. Gartner写道:
Jerry M. Gartner wrote:
问候:

什么是解决文档中路径的最佳方法,无论它在哪个路径下打开?例如:我有x.php,它包含< img
src =" images ...">,(其中包括像php代码),它可以解析
正确的图像在/下打开时的路径但是当x.php被读入文件时
在/ dir下图像不再解析,原因很明显。
Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images...">, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons.



< snip>


我不明白你的问题。但是,我更喜欢相对路径和

没有问题。


-

<?php echo''只是另一个PHP圣徒''; ?>

电子邮件:rrjanbiah-at-Y!com博客: http ://rajeshanbiah.blogspot.com/


<snip>

I don''t understand your problem. But, I prefer relative path and
had no issues with it.

--
<?php echo ''Just another PHP saint''; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/


On Sun,2006年6月18日10:24:20 GMT Jerry M. Gartner写道:
On Sun, 18 Jun 2006 10:24:20 GMT Jerry M. Gartner wrote:
[...]例如:我有x.php,它包含< img
src =" images ...">,(等等) php代码),当在/下打开时解析
正确的图像路径但是当x.php被读入文件时/ / dir下图像不再解析,原因显而易见。有了绝对的路径,这不是问题,但它是相对的路径。
[...] For example: I have x.php and it contains <img
src="images...">, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn''t an issue but it is with relative paths.




安全的一面使用绝对路径,这个肯定会工作。

为了保持你的脚本可维护,你可以制作一个配置文件,你可以把路径放进去。例如


config.php



Well to be on the safe side use absolute paths, this will definitely work.
To keep your scripts maintainable, make a configuration file where you will
put the paths in. E.g

config.php


这篇关于相对路径/绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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