DrQuincy Posted November 22, 2021 Share Posted November 22, 2021 I've got some code that gets run from various locations and the file path is stored in PW (since it varies depending on the environment). I want to be able to store a single setting that works across all environments. The problem is sometimes it's called from init.php and other times from a template. So if my setting is ../data/, this will result in things like: /MyPWSite/site/templates/../data/ /MyPWSite/site/../data/ I.e. different locations when the data is always in the same place. What would be ideal is if I can get a file path that is always from the main index.php folder (/MyPWSite/ if you go by the above example) regardless of what point in the application it's called. I've searched for this and can't find it. Is there a variable I can use? I've not really tested it but in PHP something like this would do it: dirname($_SERVER['SCRIPT_FILENAME']) I just wondered if there was already something in the PW API. Thanks. ? Link to comment Share on other sites More sharing options...
zoeck Posted November 22, 2021 Share Posted November 22, 2021 You can set your own path to your data directory ? https://processwire.com/api/ref/paths/ or you can use the root directory: $urls->root Site root: / (or subdirectory if site not at domain root) 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted November 22, 2021 Author Share Posted November 22, 2021 Ah, interesting, thanks! Link to comment Share on other sites More sharing options...
DrQuincy Posted November 22, 2021 Author Share Posted November 22, 2021 Ah, yes, this is just what I want, thanks. $paths = $config->paths; $paths->set('myData', 'my-data/'); // Relative link echo $config->paths->myData; // /Absolute/path/to/PWSite/my-data/ Thanks. ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now