johnharvey Posted May 29, 2006 Share Posted May 29, 2006 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 https://forums.phpfreaks.com/topic/10683-php-include-help/ Share on other sites More sharing options...
perezf Posted May 29, 2006 Share Posted May 29, 2006 <?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] Quote Link to comment https://forums.phpfreaks.com/topic/10683-php-include-help/#findComment-39860 Share on other sites More sharing options...
johnharvey Posted May 29, 2006 Author Share Posted May 29, 2006 [!--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.11if(!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] Quote Link to comment https://forums.phpfreaks.com/topic/10683-php-include-help/#findComment-39869 Share on other sites More sharing options...
MetalHawk Posted May 29, 2006 Share Posted May 29, 2006 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/10683-php-include-help/#findComment-39886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.