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" Quote Link to comment 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). Quote Link to comment 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"; Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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". 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.