How to Get Absolute Directory Path in PHP Script

Today, We want to share with you How to Get Absolute Directory Path in PHP Script.In this post we will show you php get directory of current file, hear for How to get absolute path on a web server using PHP we will give you demo and example for implement.In this post, we will learn about How to get the absolute path to the public_html folder with an example.

Read Also:  PHP Get Folder Path From File Path Examples

How to Get Absolute Directory Path in PHP Script

There are the Following The simple About How to Get Absolute Directory Path in PHP Script Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to get selected file path in php, so the php get root directory of website for this example is following below.

Read Also:  How To Print Last Query In PHP?

Example 1:

using dirname(__FILE__)

<?php
  include(dirname(__FILE__)."/config.php");
?>

Example 2:

using new constant called __DIR__

<?php
  include(__DIR__."/global.php");
?>

Example 3:

absolute directory path in PHP

<?php
  echo __DIR__;
?>

Bonus

echo realpath(dirname(__FILE__));

//other way
echo getcwd();

//new 
print_r($_SERVER['DOCUMENT_ROOT']);


// absolute path with file name
echo $_SERVER['SCRIPT_FILENAME'];

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to Get Absolute Directory Path in PHP Script.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Loop Binding in Vue.js With V-for

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  nested select sql
  2. Read Also:  Concat Multiple MySQL Rows GROUP_CONCAT
  3. Read Also:  php redirect new tab/window
  4. Read Also:  Object Expressions using Angular Example
  5. Read Also:  Laravel 6 Eloquent Join Multiple Tables
  6. Read Also:  MySQL IN Operators with WHERE Condition
  7. Read Also:  Woocommerce get price in custom loop
  8. Read Also:  Remove WooCommerce action Hook in Wordpress
  9. Read Also:  Loop Binding in Vue.js With V-for
  10. Read Also:  Remove WooCommerce action Hook in Wordpress
CLOSEX