Jump to content

require from another sub-directory


remenissions

Recommended Posts

Hey all, I've been having an issue with require_once from another sub-directory. Origionally I had all my php files in the same spot but I wanted to make a library to clean things up a bit.

 

Atm I am trying to access my /subFolder/frame_work/sql/dbconnect.rem.php with require once from /subFolder/frame_work/account_data/accountHandler.rem.php. I have looked around a little bit and i know requires\includes looks in relative directorys. So one obvious solution would be to include the entire path name. "var/www/subFolder/frame_work/sql/dbconnect.rem.php".

 

My problem is I will be accessing this from multiple directories and on localhost the root directory is var opposed to my server which is public_html. I like to edit my stuff in localhost before going public with it and it is going to be a real pain if I have to keep switching var to public_html in every file before I upload. Is there any other solutions I could approach? Any responses would be much appreciated. Thank you for your time.

Link to comment
Share on other sites

Give me a good reason that you can't use absolute paths :D

 

Leave relative paths for basic relationships... ../../../ gets ugly

 

$_SERVER['DOCUMENT_ROOT'] and $_SERVER['SCRIPT_FILENAME'] will help with this

Link to comment
Share on other sites

Thank you for your reply, I had never looked into this really. I saw a couple posts about it but didn't quite understand it at first glance. Just tested it with a simple

 

<?php
echo $_SERVER["DOCUMENT_ROOT"]."<br>".$_SERVER['SCRIPT_FILENAME'];
?>

 

Its just what I needed :], thank you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.