cooldude832 Posted October 1, 2007 Share Posted October 1, 2007 I'm desinging a site right now in a location that it may be be later on in life. I want to keep it so that the folder strucutre is constant and defined so i have a file called constants which looks like <?php //All constants used on the site define("ROOT","redesign/"); define("SCRIPTS","../".ROOT."scripts/"); define("SUB_FOLDER","../".ROOT."source/"); define("GRAPHICS","../".ROOT."graphics/"); define("SOURCES","../".ROOT."sources/"); define("IMAGES","../".ROOT."images/"); define("CSS","../".ROOT."css/"); define("EXT",".php"); ?> so on each page it calls the constants to know where everything is. my issue is i try calling like <?php $page = "workshops_index"; $title = "Index, Workshops"; require_once('../constants.php'); require_once(SCRIPTS.'shell.php'); ?> It picks up the file constants just fine but when it goes to load the shell it gives me an error of Failed opening required '../redesign/scripts/shell.php I don't know why its picking up the ../ as a path and not as the recall to root of the htdocs folder. I prefer not to call it from require_once("../".SCRIPTS."shell.php"); as I don't want to have to recall it on each page, nor do i think i need to any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/ Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 I've tried derrivations of the ./ ../ to move down levels, but no success Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359656 Share on other sites More sharing options...
marcus Posted October 1, 2007 Share Posted October 1, 2007 Why not call the full path and try from that? Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359658 Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 as in mydomain.com/folder/subfolder/file.php? Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359663 Share on other sites More sharing options...
willpower Posted October 1, 2007 Share Posted October 1, 2007 are you using PHP 4 or 5? Will Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359666 Share on other sites More sharing options...
marcus Posted October 1, 2007 Share Posted October 1, 2007 Root directory to complete path to file. /home/name/public_html/folder/folder/folder/another/file.ext or if you're just using a locally hosted webserver C:\path\to\this\file\i\am\serious\file.ext Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359671 Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 4.7 i believe, its not my server so this is why I'm thinking tis a .htacess issue. My folder structure is like this Root => Redesign => workshops scripts -> (shell.php, file i need to include) so workshops,scripts are subfolders of redesign which is above the root. I have a file in workshops (index.php) that needs to include the files in scripts.php, but I need to recall it consistently so that I can reuse it on any page regardless of its inherited folder position. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359673 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 i think it's picking up ../ because you define it that way: define("SCRIPTS","../".ROOT."scripts/"); i suggest always using absolute paths for include() and require(). i would replace "../" with $_SERVER['DOCUMENT_ROOT'] .. add: depending on your Apache config, you may also need a slash: $_SERVER['DOCUMENT_ROOT']."/".... etc. add: mgallforever picked up on this earlier... Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359679 Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 That is working, I just need to fix up a few things, however I don't like how it displays when i use it to call my css documents. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359681 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 okay, sort of an exception: when adding .css or .js (or similar) to HTML, you'll want to start at /. You'll need to adjust your PHP to accomodate that. the choice is between making sure your PHP is right (or site breaks entirely) or making sure your HTML is right (and site works but doesn't look so good.) in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359683 Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 I've created a solution that works for me Constants.php <?php //All constants used on the site define("ROOT",$_SERVER['DOCUMENT_ROOT']."/redesign/"); define("BASE", "http://mydomain.com/redesign/"); define("SCRIPTS", "scripts/"); define("SUB_FOLDER", BASE."source/"); define("GRAPHICS", BASE."graphics/"); define("SOURCES", BASE."sources/"); define("IMAGES", BASE."images/"); define("CSS", BASE."css/"); define("EXT",".php"); ?> I use base when writing an xhtml link/source and use root when using a php include. That makes everything happy for now. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359693 Share on other sites More sharing options...
cooldude832 Posted October 1, 2007 Author Share Posted October 1, 2007 except now i'm having an issue. If i try and call a location in my source document (located in the source folder) such as saying <img src="<?php echo IMAGES;?>Approved_shot.jpg" alt="" /> The source is outputted as IMAGESApproved_shot.jpg why is this document not picking up the constants that are defined. I do not want to reinclude the constants on this document as its a child of the larger one. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359696 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 what do you mean the document is a child of the larger one? in a DOM sense? if they use separate PHP, you'll have to require() in both places. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359699 Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Author Share Posted October 2, 2007 this is an actual page <?php $page = "index"; $title = "Home Page"; require_once('constants.php'); require_once(SCRIPTS.'shell.php'); ?> and shell says <?php session_start(); require_once("functions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="<?php echo CSS;?>index.css" /> <title>Mars Venus Institute: <?php echo $title;?></title> </head> <body> <div id="container"> <div id="header"> <a href="<?php echo BASE;?>index.php"> <img src="<?php echo GRAPHICS;?>logo.jpg" alt="" class="logo" /> </a> </div> <div id="sub_header"> </div> <div id="navi_menu"> <?php require("left_navi.html");?> </div> <div id="content"> <?php require(SUB_FOLDER.$page.EXT);?> </div> <div id="footer"> <?php require("footer.html");?> </div> </div> </body> </html> So from that if I look at the top page (index.php) it requires constants.php and the shell.php which includes the pages source (<?php require(SUB_FOLDER.$page.EXT);?>) which in that page is when i'm trying to use the constants and not getting any response. Make any sense? Its a third deep include is that why its losing the inital? Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359705 Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Author Share Posted October 2, 2007 I gave up and just added <?php require_once($_SERVER['DOCUMENT_ROOT']."/redesign/constants.php"); ?> to the top of each source file and its fine now. i'll call it solved, but its not really solved. Quote Link to comment https://forums.phpfreaks.com/topic/71445-solved-issue-calling-folders/#findComment-359721 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.