Jump to content


Photo

Include only works in current Dir


  • Please log in to reply
4 replies to this topic

#1 adamrg

adamrg
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 March 2006 - 06:45 PM

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!



#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 17 March 2006 - 07:26 PM

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
include('secondfold/newscript.php');
notice no starting slash, you only start the slash if you are doing absolute path
include('/home/wingnut/public_html/secondfold/newscript.php');

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

hope that helps

Ray

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 17 March 2006 - 07:51 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 adamrg

adamrg
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 March 2006 - 09:54 PM

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

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 10:15 PM

Is safe-mode enabled on this server?

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users