Jump to content

php include help


johnharvey

Recommended Posts

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

<?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) [snapback]377987[/snapback][/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]
Link to comment
Share on other sites

[!--quoteo(post=377988:date=May 29 2006, 12:07 AM:name=perezf)--][div class=\'quotetop\']QUOTE(perezf @ May 29 2006, 12:07 AM) [snapback]377988[/snapback][/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]


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.