开发者

Php directory problem in include_once()

I have a Header.php file in the /image directory. I used to write the header content which contains text and images. This Header.php file is included in all other pages of different directories and sub-directories of the php project.

My problem is that when access any page from sub-directories, the image in the header.php is not showing in t开发者_开发百科hat page.

Thanks


Use absolute URLs. Examples:

<img src="http://yoursite.com/images/image.jpg" />

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

This way, you aren't fighting against relative paths. Another thing you could do if you want to be lazy is use a <base> tag, which has it's pros and cons.


You are probably using a relative path in your include which means that header.php may or may not be included depending on whether your current file is on the "right" directory or not.

What you can do is :

  • use an absolute path in your include
  • modify your include path depending on where the current file is located in the hierarchy


Probably because in the header file you have given the hard code path of the image, which is in same directory, something like "test.jpg". That's why when header file is included in sub directory, it try to look for the test.jpg image in the same directory and doesnt find it. You can fix it by using the absolute paths.


If you use require_once() instead, the site won't load unless it finds the file. You can then have an error message that tells you exactly what didn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜