You could make use of the PHP $_SERVER
functionality and target the root directory.
Example:
$sort_data = get_sort($_SERVER['DOCUMENT_ROOT'].'/data/profiles/name.cms','¦');
It's important to note that what's actually defined as the root directory is defined in your configuration file.
'DOCUMENT_ROOT' - "The document root directory under which the current
script is executing, as defined in the server's configuration file."
Source here.
UPDATE AS PER YOUR COMMENT:
Thank you for your help, I already tried it but it's getting whole
xampp directory, so it didn't work.
If you ever take your project "live", the $_SERVER['DOCUMENT_ROOT']
functionality should work. The reason why it doesn't work for you right now, is because you have a "project structure" in your root
directory. I.e. localhost/myproject/index.php
. What you meant by root
is actually the project folder and not the actual root
folder.
In that case, you can try 3 different options.
- An absolute path without using the PHP reserved variable
$_SERVER
to find it.
Example:
$sort_data = get_sort('/data/profiles/name.cms','¦');
- Manually manipulate the directory path.
Example:
$sort_data = get_sort('../data/profiles/name.cms','¦');
You can add as many "level up", i.e. ../
, as it takes to get to your desired starting point and then locate the folder.
- Define your own "root" path variable.
Example:
$my_root = $_SERVER['DOCUMENT_ROOT'].'/myproject';
You can now use $my_root
with your path, like so:
$sort_data = get_sort($my_root.'/data/profiles/name.cms','¦');