Jump to content

[SOLVED] Issue Calling folders


cooldude832

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.