我正在尝试在本地主机上创建一个根目录(使用xampp),以便可以链接到从子文件夹中的根目录中找到的图像和文件夹。所以我的目录就像下面看到的那样。
另外,当网站上传到网络上时,这种方法会起作用吗?或者我必须将文档根改为http://链接到我的网站?
我的网站 ------- [f] index.html [f] logo.html [F] css - > [f] main.css [F] news - > [F] 1 - > [f] 1.html [F]图片 - > logo.html将包含在每个html页面上使用PHP。[b] logo.jpg因此,如果我将index.html包含在index.html&新闻/ 1 / 1.html链接到图像不起作用,因为新闻文件是在不同的文件夹和链接到图像文件夹的变化。
我试过这个使用PHP,但似乎我做错了:
<?php $ root = $ _SERVER ['DOCUMENT_ROOT']。' /我的网站/'; echo $ root。'/ images / logo.jpg'; ?>解决方案
$ _ SERVER ['DOCUMENT_ROOT '] 为您提供真正的文件系统路径,而不是Apache返回的路径。
要链接到资源,您需要使用HTTP路径。如果你想从根连接你只需要像 /images/logo.jpg
I am trying to create a root directory on my localhost(using xampp) so that I can link to images and folders found on the root from subfolders. So my directory is built like seen below.
Also, would this method work when the site is uploaded on the web? or would I have to change document root to links to my site?
F = folder f = file
My Site ------- [f] index.html [f] logo.html [F] css -> [f] main.css [F] news -> [F]1 -> [f] 1.html [F] images -> [f]logo.jpglogo.html will be included using PHP on every html page. So if I include the logo.html in both index.html & news/1/1.html link to image doesn't work since the news file is on a different folder and link to the images folder changes.
I tried this using PHP but it seems I am doing it wrong:
<?php $root = $_SERVER['DOCUMENT_ROOT'].'/My Site/'; echo $root .'/images/logo.jpg'; ?>解决方案
$_SERVER['DOCUMENT_ROOT'] gives you the real file-system path, not the path returned by Apache.
To link to the resource you need to use the HTTP path. If you want to link from the root you just need something like /images/logo.jpg
更多推荐
设置从子文件夹访问文件的根目录?
发布评论