How to Get the Absolute Path to the Public_HTML Folder

How to get absolute path to public_html folder

Use / at the start.

include('/header.php');

This will always include the header.php from the root folder.

path question for creating html file under ~/public_html

An absolute path can be specified by beginning the path with a forward slash (/). This will allow you to refer to documents underneath your document root.

Here is a link to an article on absolute vs. relative paths in HTML.

Edit: in response to your update - the reason you can access pic1.jpg as ../pic/pic1.jpg from doc1.html is that doc1.html lives in /doc/, so moving up one directory and then down into pic will bring you to pic1.jpg. Similarly, since your document root is ~/public_html/, you can access pic1.jpg as /pic/pic1.jpg from any html file. /pic will be interpreted as ~public_html/pic/.

Path to Files on server

something I found, If you have PHP then you can use this to get absolute path

<?php
$path = getcwd();
echo "This Is Your Absolute Path: ";
echo $path;
?>

example :- /home/user/public_html/test/test.php.

refrence :- Check this

Find file path and include it

Use the following function to get a path from directory depth

function get_include_path($file_name)
{
$folder_depth = substr_count($_SERVER["PHP_SELF"] , "/");
$directory_level = 1; //If file exist in folder after root use 2
if($folder_depth == false)
{
$folder_depth = 1;
}
return str_repeat("../", $folder_depth - $directory_level).$file_name;
}

Absolute Path of Php Files on server

give path like this for php file,

$_SERVER["DOCUMENT_ROOT"]."/path/";

and for css file,

<link rel="stylesheet" type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"] ?>/dist/css/tab.css"/> 

Get an absolute file path

In Ajax request i have changed url like this

url: location.protocol + "//" + location.host + "projectname/foldername/filename.php"

Then it worked perfectly



Related Topics



Leave a reply



Submit