Jump to content


Photo

PHP includes fine in one place but has error when moved under folders?


  • Please log in to reply
3 replies to this topic

#1 minkbooks

minkbooks
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 August 2006 - 12:21 PM

Hi there
I have just started playing around with PHP includes and have tested it.
When I do it under something like my homepage, its fine. But when I start to create folders and place it under there, an error message keeps coming.
For example.. if I place <? include("/includes/foot.php") ?> in index.php it works fine.
If I create a folder, then copy and paste the exact some thing on a doc and save it under this new folder (so now its something like /about/index.php), an error comes up about something like not being able to open the stream or something.

I'm really sorry if this question has already been asked, but I dont really know what the term is so couldnt do a search.
Thanks in advance.
Kind regards

#2 obsidian

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

Posted 28 August 2006 - 12:31 PM

take a little time studying the manual entry for include(). it doesn't take absolute paths very well. if you're looking to include a file from different locations, you really ought to try and declare a relative path based on the current directory. so:
<?php
// if you are trying to include from your root folder:
include("./includes/foot.php");

// if you are trying to include from /about/index.php:
include("../includes/foot.php");
?>

hope this helps
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

#3 minkbooks

minkbooks
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 August 2006 - 11:24 AM

Thanks a gazillion! It worked, thank you so much.

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 29 August 2006 - 12:03 PM

If you need to use absolute paths, use realpath() before calling include/require:

<?php include realpath('/path/to/file.php'); ?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users