Jump to content

Include only works in current Dir


adamrg

Recommended Posts

I can't figure out what's going wrong here.
I'm using Ensim on Fedora and one of my sites isn't allowing me to include from a folder other than the one the current php script is in.

include 'file.php'; //works
include 'directory/file.php'; //doesn't work
include(getenv('DOCUMENT_ROOT').'/directory/file.php'); // doesn't work

Any ideas?
Thanks!

Link to comment
https://forums.phpfreaks.com/topic/5176-include-only-works-in-current-dir/
Share on other sites

you have to either reference the file from the current location or use the absolute path

example

file structure

/home/wingnut/public_html/secondfold
if your file is in the public_html folder and you want to get file newscript.php in the secondfold then it would be
[code]include('secondfold/newscript.php'); [/code]
notice no starting slash, you only start the slash if you are doing absolute path
[code]include('/home/wingnut/public_html/secondfold/newscript.php');[/code]

lets say you are in the secondfold folder and want to reference a file in the base folder(public_html)
[code]include('../myfile.php');[/code]
the ../ will go back one level and work from there

hope that helps

Ray
as mentioned above, include uses relative links. with that being said, i don't know why your "include 'directory/file.php';" example won't work. it seems straight forward as long as you're not referencing an absolute pathin your "directory". if you're after absolute paths, take a look at using virtual() instead, but it's not usually recommended.
Thanks for you help!

I try to keep all my links reletive, and I'm still having an issue with my current script. I thought there must be some php setting or apache permissions that may be out of wack, but after building a simple test script, everything works just the way you guys explained.


I don't understand why my script refuses to work.. ill have a drink and start again.
Thanks...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.