编辑:感谢你的回答,我意识到,当我使用FallbackResource从index.php中提供所有页面时,每次加载脚本时,_$SERVER['REQUEST_URI']都会更新。我将根文件夹存储在一个文本文件或数据库条目中,以供index.php访问。
再次感谢
我想知道如何从$GLOBALS['rooturi'] = $_SERVER['REQUEST_URI']获取固定值,因为当我调用它时它会更新。
我在我的index.php中设置了一个根路径,用于在另一个脚本中包含图像。我尝试过使用__DIR__."/images/",但我不需要文件系统的位置(C:\xampphtdocsfile1file2WebSiteImages),而是URL版本(/website/images/)
$GLOBALS['rooturi'] = $_SERVER['REQUEST_URI'];问题是当我在另一个脚本中调用它时,它使用了新的脚本$_SERVER['REQUEST_URI'] ie。(网址/images/3/images/3)
我在FallbackResource index.php中使用.htaccess
提前感谢
发布于 2017-03-23 10:35:55
在文件中声明全局变量,该文件包含在每个脚本的开头,例如配置文件中。
/site
/site/config.php
/site/index.php
/site/subdir
/site/subdir/anotherfile.php例如:
config.php
<?php
$cfg = new stdClass();
$cfg->rooturi = $_SERVER['HTTP_HOST'].'/siteroot';
?>index.php
<?php
require_once('config.php');
echo $cfg->rooturi;
function somefunction(){
global $cfg;
echo 'In function '.$cfg->rooturi;
}
?>subdir/antherfile.php
<?php
require_once('../config.php'); // see '../' to go one level above as this file is in a subdirectory
echo $cfg->rooturi;
function somefunction(){
global $cfg;
echo 'In function '.$cfg->rooturi;
}
?>。。
发布于 2017-03-23 10:58:44
你可以在你的index.php中尝试一下
$path = str_replace('index.php', '', $_SERVER['PHP_SELF']);
$baseUrl = 'http://' . $_SERVER['SERVER_NAME'] . $path;
$GLOBALS['rooturi'] = $baseUrl;然后加载镜像:
<img src="<?php echo $GLOBALS['rooturi'] ?>/images/something.png" />https://stackoverflow.com/questions/42965665
复制相似问题