KingOfHeart Posted January 7, 2013 Share Posted January 7, 2013 If I'm in a subfolder on my site how do I call a file from the base folder? I'm in the folder "Scripts" for example and I want to call a function from the parent folder. I know you could use "../" if I remember right, but I'm looking for a php function. It would use scripts something like this... include $basefunction . "/index.php" Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/ Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 I'm having a hard time understanding your question. Typically you would define the base application directory. That way your paths and includes are always consistent. So instead of having random "../", "../../someotherdir/blah", etc spread out in your code, it would be more like $basedir/someotherdir/blah. $basedir would be the absolute path, not a relative one (../ is relative). Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403842 Share on other sites More sharing options...
KingOfHeart Posted January 7, 2013 Author Share Posted January 7, 2013 You sure that's it? I just used this and got an error. require $basedir . "/db.php"; but this works,, require "../db.php"; Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403868 Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 What did you set $basedir to? What is your directory structure? Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403870 Share on other sites More sharing options...
KingOfHeart Posted January 7, 2013 Author Share Posted January 7, 2013 You have to set it? What do I set it to? That's the command I'm looking for Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403877 Share on other sites More sharing options...
Christian F. Posted January 7, 2013 Share Posted January 7, 2013 I think you'll find your answer in the PHP manual page for the $_SERVER superglobal. Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403895 Share on other sites More sharing options...
KingOfHeart Posted January 7, 2013 Author Share Posted January 7, 2013 Tried different commands and nothing seemed to work as good as ../ so I guess I'll just continue using that method. Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403902 Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 You set it to the physical location of the first directory of your application. So if your application resides in "/var/www/someapplication", then you set your $basedir to "/var/www/someapplication". Link to comment https://forums.phpfreaks.com/topic/272788-main-folder-base-commandi-cant-think-of-what-to-call-it/#findComment-1403934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.