abdfahim Posted July 24, 2006 Share Posted July 24, 2006 I new in php programming. I want to include a php file (top.php) into another (body.php). The file top.php is one level up. so the code looks like .......//Code for body.phpinclude "../top.php";......Now the problem arises is, when I open body.php in a browser, it can't find the images attached in top.php. What can I do? Plz help me Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/ Share on other sites More sharing options...
ChaosXero Posted July 24, 2006 Share Posted July 24, 2006 Check that the images in ../top.php are loading correctly from top. If not, then check the links. Can you post ../top.php if you need more help? Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62813 Share on other sites More sharing options...
Chips Posted July 24, 2006 Share Posted July 24, 2006 location of top.php = root/location of body.php = root/nextfolder/Then your include is right:include '../top.php';So i'd look at your top.php code, and find out where it's pointing to the images!If you direct your browser to top.php, does it display all images correctly? If so, then that maybe your problem! It is the image path relative to the body.php path, and NOT the top.php path ;) Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62817 Share on other sites More sharing options...
mainewoods Posted July 24, 2006 Share Posted July 24, 2006 If you are going to include top.php in a lot of files at different directory levels, you will have to make the links in top.php absolute, not relative. Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62818 Share on other sites More sharing options...
abdfahim Posted July 24, 2006 Author Share Posted July 24, 2006 ok ... i include my my top.php file and body.php file with this ... images of top.php file works good when i include top.php in files of same folder. But when i include it from different folder, the browser look for images in the folder where body.php resides, even if I use full url .. like//code of body.php (which is in http://localhost/web/forum)include "http://localhost/web/top.php";....[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62823 Share on other sites More sharing options...
abdfahim Posted July 24, 2006 Author Share Posted July 24, 2006 here is body.php file[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62826 Share on other sites More sharing options...
Chips Posted July 24, 2006 Share Posted July 24, 2006 Then you'll have to use an absolute path to the images instead:[code]<img src="http://www.servername.com/path/to/images/image.jpg" />[/code] Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62834 Share on other sites More sharing options...
mainewoods Posted July 24, 2006 Share Posted July 24, 2006 yes, that's what I meant, you will have to make the image paths in top.php absolute. Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-62835 Share on other sites More sharing options...
abdfahim Posted July 25, 2006 Author Share Posted July 25, 2006 Thanx all... it works when I make all links absolute in top.php. But i wonder if it is possible to do same work with relative links in top.php? I guess not :(. And will it take longer time to load the images when I use absolute link then relative link? Link to comment https://forums.phpfreaks.com/topic/15487-solved-problem-with-include-command-plz-help/#findComment-63220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.