Jump to content

How do you deal with file paths in PHP?


kmaid

Recommended Posts

Hi i am quite new to PHP. I have lots of experience in C++ Delphi and a few other languages however working out what the path to a file is from various scripts is constantly confusing me especially when i am referring to files in a php file i have included in another PHP file. How do you all deal with this? I don’t want to give the full file path each time as these php files will be on 3-4 servers possibly more so i don’t want to have to have everything in a certain place. I was thinking about defining a constant of the base directory for everything but it seems a little extreme for something that should be quite simple.

 

Thanks

Kmaid

 

Link to comment
https://forums.phpfreaks.com/topic/70199-how-do-you-deal-with-file-paths-in-php/
Share on other sites

I define my system root as a property in my config object. Then I just add it ass a prefix to anything that requires a path with something like this:

 

<?php
$file = $Config->item('system_root') . 'path/to/file.php';
?>

 

You could also just use a global variable or something.

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.