设置从子文件夹访问文件的根目录?

编程入门 行业动态 更新时间:2024-10-21 16:28:11
本文介绍了设置从子文件夹访问文件的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

设置从子文件夹访问文件的根目录?

本文发布于:2023-11-09 21:07:37,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   文件夹   文件   从子

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!