Determine Windows drive letter using PHP

1.4k Views Asked by At

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.

1

There are 1 best solutions below

2
Gerald Schneider On BEST ANSWER

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