简体   繁体   English

相对路径在 html 属性中不起作用。php 文件

[英]relative path not working in html attribute in .php file

I tried to use a URL in the parent directory of the root but it's not working in the HTML attribute of the PHP file.我尝试在根目录的父目录中使用 URL 但它在 PHP 文件的 HTML 属性中不起作用。

<?php 
    include ("../func.php"); // working, will include the file in the parent directory 
?>  
<img src='../testimg.png'/>  <!-- It only looks inside the current directory-->  
<img src='..../../testimg.png'/>   <!-- If I mess around with the relative path, it still looks inside the current directory-->

However, if I delete the PHP code and change the file extension to.html, the relative path in img src works normally.但是,如果我删除PHP代码并将文件扩展名更改为.html,则img src中的相对路径可以正常工作。

Why is this happening and how could I solve the problem?为什么会发生这种情况,我该如何解决这个问题? I am wondering is there any PHP configuration file I need to adjust?我想知道我需要调整任何 PHP 配置文件吗?

I have been stuck with this problem for a long time and googled a lot but didn't find a working solution.我已经被这个问题困扰了很长时间,并在谷歌上搜索了很多,但没有找到有效的解决方案。 I would be appreciated for any help.我将不胜感激任何帮助。

I tried your code in my local with the following directory structure我使用以下目录结构在本地尝试了您的代码

root_folder
    |---my_folder
        |__index.php -> (this file contained your code above)
    |---func.php
    |---testimg.png
<img src='../testimg.png'/> showed my image perfectly. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM