phpserversystemdrive-letter

Determine Windows drive letter using PHP


I looked a little bit but didn't find the answer. Is it possible to find out the servers system drive/folder without any hacks?

In the answer that you provided it's only discussed how to determine current drive, but I need to find out the system drive, where the OS installed.


Solution

  • For Windows:

    echo GetEnv("SystemDrive");
    // C:
    

    On Unix/Linux this variable doesn't exist though, but there the system "drive" is predictably just /.

    if you need the actual partition, you can try to get it with this:

    exec( 'mount |grep " / " | cut -d " " -f 1' );
    // /dev/sda1