我对php脚本中的路径有些困难,包括其他脚本和/或所包含脚本中的元素。
例如,到目前为止,在$ ROOT / index.php中,我使用header('Location: subdir/index.php');
切换到另一个脚本$ROOT/subdir/A.php
。还有一个图像$ROOT/subdir/images/pic1.png
,由A.php使用
echo "<img src='images/pic1.png'>";
现在,我想使用include("subdir/A.php");
代替标题/位置。但是,这意味着我必须将subdir路径添加到img src,因为html内容的“主路径”仍然是$ ROOT而不是$ ROOT / subdir(与header / Location:一样)。
由于图像路径取自我不想更改的数据库,因此我想将html内容的路径切换为$ ROOT / subdir。不用标题/位置就可以吗?
(我要使用include代替标题/位置的原因是,我希望几个脚本subdir / A.png,subdir / B.png可以简单地用作http://www.example.com/而不是{{3} }等。根据用户输入或其他条件,在A.php,B.php之间切换index.php ...也许有完全不同的解决方案,这应该是标准情况吗?)