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
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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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.