{"id":1077,"date":"2013-09-20T07:00:34","date_gmt":"2013-09-20T07:00:34","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1077"},"modified":"2025-05-08T22:24:58","modified_gmt":"2025-05-08T21:24:58","slug":"paths","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/files\/paths","title":{"rendered":"Paths"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Up 1 parent directory level<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;link href=\"..\/styles.css\" rel=\"stylesheet\" type=\"text\/css\" \/&gt;\n\n&lt;?php require('..\/header.php');?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">PHP Website Root directory<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $DOCUMENT_ROOT = $_SERVER&#91;'DOCUMENT_ROOT'];\n  \/\/   \"\/var\/www\/vhosts\/mydomain.com\/httpdocs\"\n\n  if (is_file($_SERVER&#91;'DOCUMENT_ROOT'] . '\/myfile.jpg'))\n    echo \"FILE EXISTS\";<\/code><\/pre>\n\n\n\n<p>This will give you the root directory of the current website (not the server root), e.g. &#8216;\/public_html\/&#8217;.<\/p>\n\n\n\n<p>If you want to access a folder above it you can do this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  require_once $_SERVER&#91;'DOCUMENT_ROOT'] . '\/..\/vendor\/autoload.php';<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">The current file<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Filesystem path &#8211; web server referenced<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  echo ( __DIR__ );\n  \/\/Example output\n  \/\/  \/home\/websiteusername\/public_html\/the-directory-this-file-is-in\n\n  echo ( __FILE__ );\n  \/\/Example output\n  \/\/  \/home\/websiteusername\/public_html\/the-directory-this-file-is-in\/this-file-name.php<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get filename from a path string<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>path = \"\/home\/httpd\/html\/index.php\";\n$FileName = basename($path);         \/\/$FileName is set to \"index.php\"\n$FileName = basename($path, \".php\"); \/\/$FileName is set to \"index\"\n\n$FileExtension = pathinfo($path, PATHINFO_EXTENSION);    \/\/$FileExtension is set to \"php\"<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Up 1 parent directory level PHP Website Root directory This will give you the root directory of the current website (not the server root), e.g. &#8216;\/public_html\/&#8217;. If you want to access a folder above it you can do this: The current file Filesystem path &#8211; web server referenced Get filename from a path string<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,111],"tags":[],"class_list":["post-1077","post","type-post","status-publish","format-standard","hentry","category-files","category-files-html"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1077"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1077\/revisions"}],"predecessor-version":[{"id":4983,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1077\/revisions\/4983"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}