bambinou1980 Posted July 20, 2015 Share Posted July 20, 2015 Hello, I would like to know if someone could help me find a solution with this path problem please. I have a file here: C:\xampp\htdocs\food\admin\crud\customers\add-customers.php In that file I have this code: <?php session_start(); $admin_permission = $_SESSION['admin_permission']; if(($admin_permission) == 1){ //Session admin ID equal 1 }else{ header('Location: '. $_SERVER['HTTP_HOST'] . '/sign-in.php'); } include dirname(__FILE__) . '/admin/includes/admin-header.php'; include dirname(__FILE__) . '/admin/includes/admin-navbar.php'; include dirname(__FILE__) . '/admin/includes/admin-functions.php'; include dirname(__FILE__) . '/db/dbconnect.php'; ?> But this code outputs the errors: Warning: include(C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 9 Warning: include(): Failed opening 'C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 9 Warning: include(C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-navbar.php): failed to open stream: No such file or directory in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 10 Warning: include(): Failed opening 'C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-navbar.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 10 Warning: include(C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-functions.php): failed to open stream: No such file or directory in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 11 Warning: include(): Failed opening 'C:\xampp\htdocs\food\admin\crud\customers/admin/includes/admin-functions.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 11 Warning: include(C:\xampp\htdocs\food\admin\crud\customers/db/dbconnect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 12 Warning: include(): Failed opening 'C:\xampp\htdocs\food\admin\crud\customers/db/dbconnect.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\food\admin\crud\customers\add-customers.php on line 12 All I need is to have all my paths starting from the path: C:\xampp\htdocs\food\, I thought this would help include dirname(__FILE__) but it looks like not.... Would you have a different solution I could try please? Thank you, Ben Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted July 20, 2015 Share Posted July 20, 2015 dirname(__FILE__) will be returning the directory of the current script, for example it will return this file path C:\xampp\htdocs\food\admin\crud\customers You will have to use dirname(dirname(dirname(__FILE__))) to get back to the food directory. The better solution would be to add your admin directory to a constant, then prefix your filepaths using the ADMIN constant, example define('ADMIN', 'C:/xampp/htdocs/food/admin'); // or as // define('ADMIN', dirname(dirname(dirname(__FILE__))) // prefix filepaths with ADMIN constant include ADMIN . '/includes/admin-header.php'; include ADMIN . '/includes/admin-navbar.php'; include ADMIN . '/admin-functions.php'; include ADMIN . '/db/dbconnect.php'; Quote Link to comment Share on other sites More sharing options...
requinix Posted July 20, 2015 Share Posted July 20, 2015 (edited) The other common tactic is to construct a path relative to the web root: include $_SERVER['DOCUMENT_ROOT'] . '/food/admin/includes/admin-header.php';PS: You can use __DIR__ in place of dirname(__FILE__), but you'd still need a couple more dirnames() around it if you tried to use that method. Edited July 20, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
bambinou1980 Posted July 29, 2015 Author Share Posted July 29, 2015 Thank you so much I just realised that I was not getting emails notification of the posts....thanks again! Ben Quote Link to comment 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.