php - How to get the absolute path to the public_html folder? - Stack Overflow

PHOTO EMBED

Fri Apr 28 2023 05:27:01 GMT+0000 (Coordinated Universal Time)

Saved by @leninzapata #php

<?php

    // Get absolute path
    $path = getcwd(); // /home/user/public_html/test/test.php.   

    $path = substr($path, 0, strpos($path, "public_html"));

    $root = $path . "public_html/";

    echo $root; // This will output /home/user/public_html/
content_copyCOPY

https://stackoverflow.com/questions/6079479/how-to-get-the-absolute-path-to-the-public-html-folder