设置从子文件夹访问文件的根目录? [英] Setting a root directory for accessing files from subfolders?

查看:203
本文介绍了设置从子文件夹访问文件的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在本地主机上创建一个根目录(使用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 http:// 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.jpg

logo.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

这篇关于设置从子文件夹访问文件的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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