0

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.

davejal
  • 6,009
  • 10
  • 39
  • 82
  • I think if you have the `COM` class, you are able to do that. Not sure if there is an command to use with `exec()`. These may be the only options. There aren't any native PHP commands (the question is why should they add that). Google can maybe help more with windows related cli commands. – Charlotte Dunois Jan 20 '16 at 11:03
  • @CharlotteDunois, what COM class? Also, on the server side we have nothing except usual php enironment, sometimes stricted to exec commands. I thought there must be some functions to do the trick. – Александр Пушкин Jan 20 '16 at 11:06
  • @RiggsFolly Possible duplicate but not 100% sure as the web root's location can be on a different drive than the OS. – Charlotte Dunois Jan 20 '16 at 11:14
  • @CharlotteDunois You have a point, I didnt grasp the `system` bit on first reading, close removed – RiggsFolly Jan 20 '16 at 11:16
  • 1
    Try looking at `$_SERVER["SystemRoot"]` although I am not sure what that will return on a UNIX environment – RiggsFolly Jan 20 '16 at 11:17
  • @CharlotteDunois, interesting info. Maybe I will use it as plan B if nothing more will be found. – Александр Пушкин Jan 20 '16 at 11:19

1 Answers1

2

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
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
  • Thanks for linux tip. Also, one more question - using GetEnv or $_SERVER can I actually find out OS name? – Александр Пушкин Jan 20 '16 at 11:26
  • 1
    You can see all available environment variables with [`phpinfo()`](http://php.net/manual/en/function.phpinfo.php), `$_SERVER` can be inspected like all variables with [`var_dump()`](http://php.net/manual/en/function.var-dump.php). – Gerald Schneider Jan 20 '16 at 11:29