including a file below my web root

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

Hi all

I hope someone can help me.

I have two files in my webroot:
FileA.php
FileB.php

In FileA.php I include FileB.php as follows:

include ('FileB.php');

It works perfectly.

Now I move FileB.php to a subfolder so that now I have:

FileA.php
subfolder/FileB.php

I now want to include the moved file into FileA.php

How would i rewrite the include statement for FileB.php since it is no longer in the web root.

thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9088
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

This should do it:

PHP Code: [ Select ]
include ('subfolder/FileB.php');
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

I tried it but it did not work
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

I found my problem

fileB.php also called a text file as follows:

$logfile = "logfile.txt";

When I changed this to:

$logfile = "subfolder/logfile.txt";

it worked OK.

This got me thinking a bit.

What would happen if FileA.php was moved to:

subfolderA/SubfolderB/FileA.php

Would things screw up.

Is there a way where I can include FileB.php, and whatever it calls up, anywhere on my website, whether it be root, subfolder, subfolderA/subfolderB, etc. so that I do not have to worry and know that it will always be called up properly.

thanks
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

I found another method that seems to work everywhere as follows:

Code: [ Select ]
include($_SERVER['DOCUMENT_ROOT'].'/subfolder/FileB.php');
$logfile = $_SERVER['DOCUMENT_ROOT'].'/subfolder/logfile.txt');
  1. include($_SERVER['DOCUMENT_ROOT'].'/subfolder/FileB.php');
  2. $logfile = $_SERVER['DOCUMENT_ROOT'].'/subfolder/logfile.txt');


Would the above be a good way to do it or is there a better way

thanks

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 51 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.