Jump to content

trouble with my file paths


ricky spires

Recommended Posts

hello,

 

i cant see why my navigation file path is not working

 

im working on my localhost:  http://localhost:8888/djsonrotation

 

my initialize file is located at http://localhost:8888/djsonrotation/includes/initialize.php

 

my navigation code is located at http://localhost:8888/djsonrotation/pages/pageContent/navigation/ddAccordion.php

 

my js is located at http://localhost:8888/djsonrotation/js/ddaccordion.js

 

 

 

if i put these on my ddAccordion.php it works

 

 

to find my initialize file
<?PHP require_once("../../../includes/initialize.php"); ?>

to find my js file
<script type="text/javascript" src="../../../js/ddaccordion.js">

 

 

this is how my initialize file looks

<?PHP
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

defined('ELEMENTS') ? null : define('ELEMENTS', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation'.DS.'pages'.DS.'contElements');

 

 

 

 

the problem is i can't seem to change ../../../  in to a file path

 

like this does not work

<?PHP require_once(include(LIB_PATH.DS."initialize.php")); ?>

 

 

i tried a couple of different file paths for my js file but they dont work either

<script type="text/javascript" src="<?php include(SITE_DOMAIN.DS."js".DS."ddaccordion.js"); ?>">

or

<script type="text/javascript" src="<?php include(SITE_ROOT.DS."js".DS."ddaccordion.js"); ?>">

 

 

i guess i could just use ../../../

 

but why are the include paths not working ????

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/
Share on other sites

Why not use absolute paths?

define('BASE_PATH', realpath('.'));

BASE_PATH will now equal the absolute path to the script that executed it.

For example if BASE_PATH is defined in /var/www/mysite/index.php

then it would equal "/var/www/mysite"

This works if your entire site is controlled through an index.php file (Like in MVC architecture etc)

 

You have a very confusing looking directory structure.. How about in the index.php (Or whatever file includes all the others) you define a constant with the site root? Then you can use it to include files like this

include SITE_ROOT.'/djsonrotation/includes/initialize.php'

In this case SITE_ROOT would be /directory/wherever/localhost/looks/for/files

It's a lot easier than trying to keep track of all those dots.

 

:( im sorry but i cant get it to work :(

 

if i do this

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

i get

/Applications/MAMP/htdocs

 

 

i put this

define('BASE_PATH', realpath('.'));

in to my initialize.php

 

but i dont understand what im ment to do with it ???

 

am i ment to do this:

define('BASE_PATH', realpath('/Applications/MAMP/htdocs'));

 

??? is this correct ???

 

 

then how do i call it ??

for example, i TRIED to do this, but it does not work

 

<script type="text/javascript" src="<?php include(BASE_PATH.DS."djsonrotation".DS."js".DS."ddaccordion.js"); ?>">

 

 

 

 

in my initialize file i have this

 

defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation');

 

so i also tried this, but it does not work

<script type="text/javascript" src="<?php include(SITE_ROOT'.DS."js".DS."ddaccordion.js"); ?>">

 

 

if i do

../../../js/ddaccordion.js

it works

 

I'm not 100% sure of the answer yet, but I'm sure you're doing something wrong.

 

You are including the JavaScript file instead of actually echo-ing it's location.

 

Your code:

<script type="text/javascript" src="<?php include(BASE_PATH.DS."djsonrotation".DS."js".DS."ddaccordion.js"); ?>">

 

What it should be?

<script type="text/javascript" src="<?php echo BASE_PATH.DS."djsonrotation".DS."js".DS."ddaccordion.js"; ?>">

I'm not 100% sure of the answer yet, but I'm sure you're doing something wrong.

 

You are including the JavaScript file instead of actually echo-ing it's location.

 

Your code:

<script type="text/javascript" src="<?php include(BASE_PATH.DS."djsonrotation".DS."js".DS."ddaccordion.js"); ?>">

 

What it should be?

<script type="text/javascript" src="<?php echo BASE_PATH.DS."djsonrotation".DS."js".DS."ddaccordion.js"; ?>">

 

Yea, you're right. I re-read the question and it made more sense this time :P

 

Ricky, in realpath('.'); the dot refers to the current directory. (Just like ".." is the parent directory). So when you do realpath('.') you're getting a string that is the path to the current directory.

Archived

This topic is now archived and is closed to further replies.

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