grahamb314 Posted October 11, 2008 Share Posted October 11, 2008 Hi all, I have a php pqge which requires a php file to connect to a database: <?php //connect to the database require('mysql_connect.php'); ?> I have moved mysql_connect.php to the previous directory so i need to change what I have for the require. How do I tell it to require the same file name, but in the previous directory? Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/ Share on other sites More sharing options...
bothwell Posted October 11, 2008 Share Posted October 11, 2008 <?php //connect to the database require('../mysql_connect.php'); ?> ? Or have I misunderstood? Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662836 Share on other sites More sharing options...
grahamb314 Posted October 11, 2008 Author Share Posted October 11, 2008 Thanks that works, so how do I go back 2 directories? Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662843 Share on other sites More sharing options...
bothwell Posted October 11, 2008 Share Posted October 11, 2008 Thanks that works, so how do I go back 2 directories? Just repeat the ../ for each level you need to go back - same with any file, not just PHP, so it works for images, stylesheets, normal pages, anything really. require('../../mysql_connect.php'); Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662852 Share on other sites More sharing options...
Lamez Posted October 11, 2008 Share Posted October 11, 2008 using, "../" will always go up in the directory tree, so you can use "../../../" and that will take you up three directory. This also used in HTML. Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662898 Share on other sites More sharing options...
dropfaith Posted October 11, 2008 Share Posted October 11, 2008 i find doing ../ gets complex past a few directorys and use this $destination = $_SERVER['DOCUMENT_ROOT']; include("$destination/template/conf.php"); Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662902 Share on other sites More sharing options...
grahamb314 Posted October 11, 2008 Author Share Posted October 11, 2008 Thanks! All working now!! Quote Link to comment https://forums.phpfreaks.com/topic/128008-solved-require-a-file-from-previous-directory/#findComment-662907 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.