Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/259614-what-would-be-the-root-of-this-path/
Share on other sites

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

 

 

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');

 

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?

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

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');

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');

 

 

 

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.