Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Functions in seperate folders.....

Status
Not open for further replies.

newphpbie

Programmer
Joined
Oct 17, 2003
Messages
110
Location
GB
Hello,

I have just created my first function which I am using to connect to the MySQL database. I have the function set up correctly and working fine...however....

I have just started to organise my pages and put them into organised folders so it's easier to find them....e.g Search Pages, Input Pages, Update Pages etc etc...

My problem is this....

When I move my files into other folders the function doesn't work anymore....it gives me this error

Code:
[b]
Warning: Failed opening '/UNWED/functions/connectfunct.php' for inclusion (include_path='.:/usr/share/pear') in /var/[URL unfurl="true"]www/html/UNWED/Search/viewallusers.php[/URL] on line 13
[/b]

/UNWED is the root folder of my web page.... I have changed the browers line in the code to look for the function in the correct place but this still doesn't work. I've also tried hard coding the connect back into the code and it works fine...

Why does it not work when the file is in another folder???

I'm running LAMP if it helps...

Any help b much appriciated....
 
Does this have something to do with PEAR???

I don't know anything about PEAR, just heard it mentioned before....

 
It won't have anything to do with PEAR unless you're using it.

It's most likely a path problem, and probably relates to the fact that since include() can operate over your entire filesystem, documentroot-relative paths may not work. What does your include invokation look like?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Code:
include("UNWED/functions/connectfunct.php");
connectfunct();

The path appears to be fine, and I've tried all the little things like putting an extra slash before UNWED etc...

Could I be missing something else?
 
on the same level I think...

I have UNWED as my main folder....

my functions are stored in

/UNWED/functions/

my file is stored in

/UNWED/Search/

I've just tried moving my function into the UNWED directory and running it from there but I still get the same error message...

Code:
Failed opening 'UNWED/connectfunct.php' for inclusion (include_path='.:/usr/share/pear') in /var/[URL unfurl="true"]www/html/UNWED/Search/viewallusers.php[/URL]

AAAAAAAAAahhhhhhhhhhhhhhaaaaaaa!!!!! Sussed it....

I've put in the whole directory string and it works....

/var/


Thought it would have picked it up from the directory root but obviously not....

So it's sorted...thanks for u'r help...

Shortcuts get me no-where......
 
No, it will pick it up from the current directory... so I'll admit I wasn't reading closely, and just provide an example...
Code:
If your file was in 
.../UNWED/search/
and you wanted a file from
.../UNWED/functions/

you would need to 
include('../functions/myfile.inc.php');

Or, as you discovered, use the complete path... which is probably preferred, but doesn't translate well to systems you need to upload to another server.

-Rob
 
Again, include() is not constrained by or even aware of your web site's document root. include() (and its relatives include_once(), require(), and require_once()) operates on your entire filesystem.

You must do one of:[ul][li]give include() a relative filesystem path to the file to be included[/li][li]give include() an absolute filesytem path to the file to be included, or[/li][li]modify your include path to include the containing directory and simply hand include() the name of the file to be included[/li][/ul]

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top