dingdong1 Posted February 22, 2013 Share Posted February 22, 2013 Hi, i need some help with directory in php, everything works fine when i use wamp with localhost, but when i ftp my files to a webhost i get this error: Warning: include_once(/admin/root.php) [function.include-once]: failed to open stream: No such file or directory in /home/username/public_html/index.php on line 2 I think that I miss something in my config.php file, but Im not really sure how I can fix this since Im very new to PHP, I only need some basic PHP atm to make stuff easier for me. admin/config.php http://pastebin.com/hZWLJJ3D index.php http://pastebin.com/VFRKGNGX Appreciate all the help i get! Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/ Share on other sites More sharing options...
AyKay47 Posted February 22, 2013 Share Posted February 22, 2013 The file that you are including on line 2 can not be found. Verify that the path to the file is correct. Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414280 Share on other sites More sharing options...
requinix Posted February 22, 2013 Share Posted February 22, 2013 That leading slash means to look in the root of the drive. It's akin to saying C:\admin\root.php. Naturally that's not where your file lives. It actually lives in /home/username/public_html/admin/root.php. So that's what you need to say. Easiest method is include_once($_SERVER["DOCUMENT_ROOT"] . "/admin/root.php"); Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414293 Share on other sites More sharing options...
dingdong1 Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) Warning: include_once() [function.include-once]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/admin/config.php) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/username/public_html/index.php on line 1 line1 <?php include_once($_SERVER["DOCUMENT_ROOT"] . "/admin/config.php"); ?> Edited February 22, 2013 by dingdong1 Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414303 Share on other sites More sharing options...
requinix Posted February 22, 2013 Share Posted February 22, 2013 Well that's certainly not normal. Okay, DOCUMENT_ROOT won't work. Next best thing is a relative path. Assuming you have PHP 5.3 or later, include_once(__DIR__ . "/admin/config.php"); Looks the same, huh? The DOCUMENT_ROOT version works by starting at the root of your website and going to the admin/config.php file from there. Using __DIR__ is relative to the file you put the code in, which could be the root or could be someplace else. Say you have a file include/config.php and want to include the admin/config.php stuff. The two methods together then look like // start at the website root, go to admin/config.php include_once($_SERVER["DOCUMENT_ROOT"] . "/admin/config.php"); // start in this directory, go up a directory, then go to admin/config.php include_once(__DIR__ . "/../admin/config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414307 Share on other sites More sharing options...
dingdong1 Posted February 23, 2013 Author Share Posted February 23, 2013 (edited) I tried again, but it just keep failing DEMO - Here you can see the errors index.php <?php include_once(__DIR__ . "/include/header.php"); ?> <?php include_once(__DIR__ . "/include/body.php"); ?> <h1>THIS IS INDEX</h1> <?php include_once(__DIR__ . "/include/footer.php"); ?> admin/ config.php <?php $title = 'DomainName'; $url = 'http://localhost'; $header = 'include/header.php'; $body = 'include/body.php'; $footer = 'include/footer.php'; ?> include/ header.php <?php include_once(__DIR__ . "/../admin/config.php"); ?> <html> <head> <title><?php echo $title; ?></title> <h1><a href="<?php echo $url; ?>">LOGO NAME</a></h1> body.php </head> <body> <nav> <ul> <li><a href="/music">Music</a></li> </ul> </nav> footer.php <footer> copyright © 2013 - <?php echo $title; ?> </footer> </body> </html> music/ index.php <?php include_once(__DIR__ . "/../include/header.php"); ?> <?php include_once(__DIR__ . "/../include/body.php"); ?> <h1>THIS IS MUSIC CONTENT</h1> <?php include_once(__DIR__ . "/../include/footer.php"); ?> Edited February 23, 2013 by dingdong1 Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414324 Share on other sites More sharing options...
requinix Posted February 23, 2013 Share Posted February 23, 2013 Assuming you have PHP 5.3 or later, You don't. include_once(dirname(__FILE__) . "/../admin/config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414328 Share on other sites More sharing options...
dingdong1 Posted February 23, 2013 Author Share Posted February 23, 2013 well my wamp have 5.4.3, so it works fine on localhost 000webhost have PHP Version 5.2.17 so maby thats why, any solution? Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414329 Share on other sites More sharing options...
requinix Posted February 23, 2013 Share Posted February 23, 2013 include_once(dirname(__FILE__) . "/../admin/config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414332 Share on other sites More sharing options...
dingdong1 Posted February 23, 2013 Author Share Posted February 23, 2013 its not working, i replaced all include_once(__DIR__ . with include_once(dirname(__FILE__) . Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414333 Share on other sites More sharing options...
dingdong1 Posted February 23, 2013 Author Share Posted February 23, 2013 Im of to sleep now, if you can test it out or something and see if you can manage to fix the problem, i would very much apreciate it. if not i want to say thanks for all the help you gave me so far , even tho it didn't work out for me. Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414335 Share on other sites More sharing options...
requinix Posted February 23, 2013 Share Posted February 23, 2013 Not working how? Error messages? The site is still showing the __DIR__ version. Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414339 Share on other sites More sharing options...
dingdong1 Posted February 23, 2013 Author Share Posted February 23, 2013 didnt work last night maby i screwed up somewhere, anyway it worked now with include_once(dirname(__FILE__) . thank you. Quote Link to comment https://forums.phpfreaks.com/topic/274836-php-directory-help/#findComment-1414404 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.