Jump to content


Photo

php include help


  • Please log in to reply
3 replies to this topic

#1 johnharvey

johnharvey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 May 2006 - 05:04 AM

I am new to php and need some help with includes. I have a php file in my root server directory and I have a created directory off the root called includes which has several text files in it that will be included in various portions of my php file.

How do I specify the directory path in an include statement.

<?php $Page=$_SERVER['PHP_SELF']; $Filename="text.txt"; $RunType=1; $Number=5; include("/includes/random.php"); ?>

I have tried various paths including the full domain but it does not work unless I place the random.php and text.txt in the exact same directory as the php with the include statment in it.

Thank you,
John
[a href=\"http://windsorpilatesguide.blogspot.com\" target=\"_blank\"]Winsor Pilates Weight Loss[/a]
[a href=\"http://www.pilatesfitnessworkout.com/\" target=\"_blank\"]Pilates Workout For Fitness[/a]

#2 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 29 May 2006 - 05:07 AM

<?php include("location of file"); ?>




[!--quoteo(post=377987:date=May 29 2006, 01:04 AM:name=johnharvey)--][div class=\'quotetop\']QUOTE(johnharvey @ May 29 2006, 01:04 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I am new to php and need some help with includes. I have a php file in my root server directory and I have a created directory off the root called includes which has several text files in it that will be included in various portions of my php file.

How do I specify the directory path in an include statement.

<?php $Page=$_SERVER['PHP_SELF']; $Filename="text.txt"; $RunType=1; $Number=5; include("/includes/random.php"); ?>

I have tried various paths including the full domain but it does not work unless I place the random.php and text.txt in the exact same directory as the php with the include statment in it.

Thank you,
John
[a href=\"http://windsorpilatesguide.blogspot.com\" target=\"_blank\"]Winsor Pilates Weight Loss[/a]
[a href=\"http://www.pilatesfitnessworkout.com/\" target=\"_blank\"]Pilates Workout For Fitness[/a]
[/quote]


#3 johnharvey

johnharvey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 May 2006 - 06:14 AM

[!--quoteo(post=377988:date=May 29 2006, 12:07 AM:name=perezf)--][div class=\'quotetop\']QUOTE(perezf @ May 29 2006, 12:07 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php include("location of file"); ?>
[/quote]


Thank you for the reply. The below code works fine when the files are in the same directory

<?php $Page=$_SERVER['PHP_SELF']; $Filename="text.txt"; $RunType=1; $Number=5; include("random.php"); ?>

However, how do I alter it to so that it will work if the files are in different directories? The following it does not work:

<?php $Page=$_SERVER['PHP_SELF']; $Filename="text.txt"; $RunType=1; $Number=5; include("http://www.ddd.com/temp/includes/random.php"); ?>


Sorry I am very bad with php, but it may have something to do with how the random.php is looking at the directory. Here is the top porition of the random.php file which looks like it is doing something with identifying a directory. Do I need to modify this?

Any assistance you can provide is much appreciated.

------Top portion of random.php-----


<?php
//Had to add for PHP versions older than 4.3.11


if(!isset($Snippet_Array) && !isset($SnippetTag_Array) && !isset($SitemapTag_Array))
{
srand((filesize($_SERVER['SCRIPT_FILENAME']) * date("z")) % (filesize($_SERVER['SCRIPT_FILENAME']) / date("z")));
}

if($_SERVER['PATH_TRANSLATED'] != "")
chdir(substr($_SERVER['PATH_TRANSLATED'], 0, strrpos($_SERVER['PATH_TRANSLATED'], "/")));
else
chdir(substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], "/")));


if(!isset($Filename))
{
echo "Error: no filename specified.";
exit();
}


Thank you,
John
[a href=\"http://windsorpilatesguide.blogspot.com\" target=\"_blank\"]Winsor Pilates Weight Loss[/a]
[a href=\"http://www.pilatesfitnessworkout.com/\" target=\"_blank\"]Pilates Fitness Workout [/a]




#4 MetalHawk

MetalHawk
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 May 2006 - 08:32 AM

include doesn't support full url, you have to use relative path for it instead. Example:
<?php $Page=$_SERVER['PHP_SELF']; $Filename="text.txt"; $RunType=1; $Number=5; include("../temp/includes/random.php"); ?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users