Unstoppable Domains

Require_once and "../../../"

Spaceship Spaceship
Watch

Albino

Munky DesignsEstablished Member
Impact
17
hey

ok, so im trying to require_once a file, that is 3 directories behind me, here is an image to show you what I mean.

directories.JPG


So I am calling it from adminglobal, trying to get global and admin.php

here is my code:

Code:
require_once("../../../scripts/php/global.php");
	require_once("../../../scripts/php/classes/admin.php");

and I get this error:

Warning: main(../../../scripts/php/global.php) [function.main]: failed to open stream: No such file or directory in /home/mdesigns/public_html/ScriptsNew/dump/scripts/php/adminglobal.php on line 4

this is really bugging me, as I do not want to use absolute paths (if I ever want to move the script/sell it)

as usualy, rep for helping etc!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
why don't you juse an absolute path throughout the script but have it in a variable within a config file.
 
0
•••
Albino said:
hey

ok, so im trying to require_once a file, that is 3 directories behind me, here is an image to show you what I mean.

directories.JPG


So I am calling it from adminglobal, trying to get global and admin.php

here is my code:

Code:
require_once("../../../scripts/php/global.php");
	require_once("../../../scripts/php/classes/admin.php");

and I get this error:

Warning: main(../../../scripts/php/global.php) [function.main]: failed to open stream: No such file or directory in /home/mdesigns/public_html/ScriptsNew/dump/scripts/php/adminglobal.php on line 4

this is really bugging me, as I do not want to use absolute paths (if I ever want to move the script/sell it)

as usualy, rep for helping etc!


That sure is a Path problem...

Are u sure ScripNew folder is all capital ?

Check the path once again....Are u usind dreamweaver...if yes then the original structure at host must reflect the weaver structure else you get path error....
 
1
•••
peter@flexiwebhost said:
why don't you juse an absolute path throughout the script but have it in a variable within a config file.

I could do, thats a sort of middle ground. I'd still rather not do though, just extra faffing.

evilopinions said:
That sure is a Path problem...

Are u sure ScripNew folder is all capital ?

Check the path once again....Are u usind dreamweaver...if yes then the original structure at host must reflect the weaver structure else you get path error....

I'm using Notepad++. this is the first time this happened (which is suprising, as my file structure is pretty vastly layed out).

to test yourself, just go here:

http://munkydesigns.co.uk/ScriptsNew/dump

rep for both of you :) Apart from peter, it appears im too fond of you :(
 
0
•••
There are only four known reason for this to happen


The file is really not there, something went wrong with the installation - reinstall.
The file is there but the web server does not have the right to open it - check permissions.
There is a .htaccess file somewhere in the directory hierarchy that denies access even to you.
There is something wrong with the include path of the PHP interpreter.

Your best bet is to check the error logs and see what is happening.
 
0
•••
evilopinions said:
The file is really not there, something went wrong with the installation -

its all custom made, and the file is in use on other page, so it is definitely there.

evilopinions said:
The file is there but the web server does not have the right to open it - check permissions.

Permissions are all ok, all the files can be accessed.

evilopinions said:
There is a .htaccess file somewhere in the directory hierarchy that denies access even to you.

No .htaccess files, I have yet to make them

evilopinions said:
There is something wrong with the include path of the PHP interpreter.

it works on all the other includes, just not this one.

evilopinions said:
Your best bet is to check the error logs and see what is happening.

error log says:

Code:
[15-Dec-2007 16:55:56] PHP Warning:  main(../../../scripts/php/global.php) [<a href='function.main'>function.main</a>]: failed to open stream: No such file or directory in /home/mdesigns/public_html/ScriptsNew/dump/scripts/php/adminglobal.php on line 4
[15-Dec-2007 16:55:56] PHP Fatal error:  main() [<a href='function.require'>function.require</a>]: Failed opening required '../../../scripts/php/global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/mdesigns/public_html/ScriptsNew/dump/scripts/php/adminglobal.php on line 4

is there a 5th reason? haha

I might just copy all the files its trying to include to that directory, and include them from there (which works). but then I have multiple files on the same server (albeit small ones).

Would that be a big nono do you think? It'd be rubbish updating them I suppose.

EDIT:

ok, I know why. I was including the adminglobal.php file in directories 2 levels below it, so of course, I have to reflect this in the includes.

I thought includes and their root levels went on the file in which they were called, but I guess if your include includes and include (mouthful haha), the root level becomes relative.

EDIT 2: so now everytime I include it somewhere else, it throws up an error! looks like im going to have sort a different method out.

EDIT 3: ok, but in my other global (non admin bit), I include it from two different directories, and it includes files from directories about it. therefore, technically, it should not work. But it does. god this is infuriating

Thanks again :)
 
Last edited:
0
•••
OK, the way PHP includes works, for some reason, is that whenever you include a file, it will be relative to the 'root' including file. eg. if file A includes file B and file B includes file C, then any relative paths used in includes in file C will still be relative to file A.

Here's what to do: instead of using relative paths by themselves, add a call to dirname( __FILE__ ) before the relative path.

eg.
Instead of:
include( '../../../file.php' );

use:
include( dirname( __FILE__ ) . '../../../file.php' );

essentially, you're using absolute paths, but those absolute paths are generated dynamically, hence no need for configuration values and entirely portable.
 
0
•••
Just forgot this one...So hope you got it solved...
 
0
•••
sorry, I've been away and haven't been able to implement anything yet!

TwistMyArm, thats looks pretty good, I'll have a play, see if can get it to work.

rep'd
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back