2016-09-16 205 views
0

我想通过header.php文件显示与图像文件相同的目录。如何显示通过子目录PHP文件在超目录PHP文件中显示的图像?

以我的header.php使用< IMG SRC = “image.jpg的”>显示图像, 但我的index.php是子目录,并使用包括( '../的header.php');

=== image.jpg 
=== header.php 
=== new folder 
====== index.php 

是的,图像不会显示这种方式。 因为在index.php中也会有< img src =“image.jpg”>像我包含的header.php。

无论如何显示从index.php通过header.php图像?

回答

0

,如果你没有在这两个和的header.php index.php的只是设置

<img src="../image.jpg"> 

对接,以显示图像,如果你想在header.php中显示图像和index.php文件也

我想这可能帮助:

<img src="/your_website_name/image.jpg"> 

所以不管,你在哪里 - >中的header.php或index.php文件,您可以使用相同的代码:

<img src="/your_website_name/image.jpg"> 

或使用PHP

<img src="/<?php echo $_SERVER['SERVER_NAME'] ?>/image.jpg"> 
0

它包括标题页,但它会在索引页猪病图像,所以用“../image.jpg”。