ricky spires Posted February 7, 2012 Share Posted February 7, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/ Share on other sites More sharing options...
ttocskcaj Posted February 7, 2012 Share Posted February 7, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1315390 Share on other sites More sharing options...
ricky spires Posted February 7, 2012 Author Share Posted February 7, 2012 Hello. Thanks for your reply. I will have a go at doing that later today but, out of Curiosity whats wrong with my code ? why is it not working ? thanks rick Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1315426 Share on other sites More sharing options...
ricky spires Posted February 7, 2012 Author Share Posted February 7, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1315579 Share on other sites More sharing options...
ricky spires Posted February 8, 2012 Author Share Posted February 8, 2012 anyone ? Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1315764 Share on other sites More sharing options...
PaulRyan Posted February 8, 2012 Share Posted February 8, 2012 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"; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1315780 Share on other sites More sharing options...
ttocskcaj Posted February 12, 2012 Share Posted February 12, 2012 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/256587-trouble-with-my-file-paths/#findComment-1317170 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.