我的问题类似于PHP include file strategy needed。我有以下文件夹结构:PHP包含来自根文件夹中不同子目录的文件
/root/pages.php
/root/articles/pages.php
/root/includes/include_files.php
/root/img/images.jpg
在 “/根” 所有页面和 “/根/条” 目录有 “header.php文件” 和“页脚.php“文件,它们存储在”/root/includes“目录中。
页眉和页脚页面都包含存储在“root/img/”目录中的图像。
正如所建议的:
How to use a PHP includes across multiple directories/sub directories with relative paths
我试过**dirname**
解决方案和$_SERVER['DOCUMENT_ROOT]
解决方案,包括存储在根目录和文章文件的页眉和页脚子目录。
不过,我遇到问题时,我尝试使用这两种方法(页眉和页脚文件中)链接图片:
<img src=" <?php echo dirname(__FILE__). '/img/image.jpg';?>">
浏览器无法显示图像,并引发以下错误:
locally: Not allowed to load local resource: file:///C:/root/img/image.jpg
on the server: GET http://host.com/home/public_html/root/img/image.jpg 500 (Internal Server Error)
我检查了网址,他们似乎是正确的。在搜索解决方案后,我发现Chrome出于安全原因阻止显示包含完整文件路径的文件。
我该如何解决这个问题?或者有没有其他方法将文件(包括图像)包含到存储在任何子目录中的文件中?
没有解决它。我遇到了同样的问题。不让我用file://协议打开文件。 –