Shadowing Posted March 24, 2012 Share Posted March 24, 2012 hey guys im still having a issue with using the root path when requiring external files. So i can use one path and never have to worry about this issue. require("/functions/function_battle.php"); the file is located here C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php i dont understand (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') im suppose to be including the php folder or something? Fatal error: require() [function.require]: Failed opening required '/functions/function_battle.php' (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') in C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php on line 2 Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/ Share on other sites More sharing options...
mitramcc Posted March 24, 2012 Share Posted March 24, 2012 What is the path from the file that is calling require("/functions/function_battle.php"); Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330711 Share on other sites More sharing options...
jcbones Posted March 24, 2012 Share Posted March 24, 2012 echo __FILE__; This will show you the full path to your current script. Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330712 Share on other sites More sharing options...
Shadowing Posted March 24, 2012 Author Share Posted March 24, 2012 Alright this is the way this is going but yah its the last file in the chain that is causing the issue. all my other pages work fine on my site that is requring battle.php and then having battle.php use function_battle.php. this is the page im viewing C:\Software\XAMPP\xampp\htdocs\System_Lords\messages\inbox.php then on that file im including this file "which is a menu" require("../menu.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\menu.php and on the file above "the menu" has this file included include_once("/include/battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php and on the file above "battle.php" has this file included require("/functions/function_battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330717 Share on other sites More sharing options...
mitramcc Posted March 24, 2012 Share Posted March 24, 2012 Alright this is the way this is going but yah its the last file in the chain that is causing the issue. all my other pages work fine on my site that is requring battle.php and then having battle.php use function_battle.php. this is the page im viewing C:\Software\XAMPP\xampp\htdocs\System_Lords\messages\inbox.php then on that file im including this file "which is a menu" require("../menu.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\menu.php and on the file above "the menu" has this file included include_once("/include/battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php and on the file above "battle.php" has this file included require("/functions/function_battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php then if is the battle.php that is calling the function battle and this file is in C:\Software\XAMPP\xampp\htdocs\System_Lords\include you will need to go back one folder to find the file try require('../functions/function_battle.php'); Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330718 Share on other sites More sharing options...
Shadowing Posted March 25, 2012 Author Share Posted March 25, 2012 Yah i tried that before and it makes all my other pages not work since in those chains it doesnt need to look up one folder. So I guess there is no way to set a path for require so it doesnt matter what folder i have stuff in? Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330873 Share on other sites More sharing options...
mitramcc Posted March 25, 2012 Share Posted March 25, 2012 echo __FILE__; This will show you the full path to your current script. Then u can use the __FILE__ to know where you are and addapt the include... you can also do this with file_exists("path")http://php.net/manual/pt_BR/function.file-exists.php Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1330906 Share on other sites More sharing options...
Shadowing Posted March 26, 2012 Author Share Posted March 26, 2012 alright I get this when I use echo_file_; which it didnt tell me anything I didnt know. so is there away to put a constants in the require path? C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php I was reading some stuff online and is there a way where i can add this to the require file then? require("/function_battle.php"); I was reading a site that says i can do something like this but it doesnt work for me include(dirname(__FILE__).'/function_battle.php'); Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1331202 Share on other sites More sharing options...
jcbones Posted March 26, 2012 Share Posted March 26, 2012 Set a constant with your root location. Then address all of your included files by the root. //in your config file. DEFINE('ROOT_DIR','C:/Software/XAMPP/xampp/htdocs/System_Lords/'); //in your other files require(ROOT_DIR . 'functions/function_battle.php'); Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1331344 Share on other sites More sharing options...
kicken Posted March 26, 2012 Share Posted March 26, 2012 PHP's filesystem functions work with a filesystem path, not a url path. In a filesystem path, the root (/) references the root of the drive, which in your case is C:\. So when you do require('/function_battle.php') you are attempting to include the file located at C:\function_battle.php. You need to either use a relative path or define a constant to your site's root directory and use it as a prefix when including files. Quote Link to comment https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/#findComment-1331375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.