开发者

Formatting PHP include file's resource for use across multiple directory levels

I am attempting to use an include for my footer across all pages on my site. However, as the pages utilising the footer are spread across a variety of different directory levels the image paths in the footer are not correct for the pages in sub directories (assuming my image path is src="images/image1.jpg" and my image folder is in the lowest directory).

I thought about using $_SERVER['DOCUMENT_ROOT'] and building my image filenames from there but it seems a bit long winded. Is this th开发者_如何学运维e standard way of overcoming this or am I missing something!?

Thanks,

Rich


I would recommend consolidating your images in a single root level directory. If you want to organize them under that then you can add subfolders. If you really need to keep the image sin the individual folders youre including from then you can always symlink those folders into the top level images folder. This way you can always use absolute URLs to reference images, js, css.

The other way would be to write a helper function you can call that will determine the proper path based on $_SERVER['DOCUMENT_ROOT'] and the path to the file youre including (realpath(dirname(__FILE__)). That way you can just call the function instead of reqriting the code to figure it out in every file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜