I'm writing a simple web app in PHP that needs to have write access to a directory on the server, if the directory isn't writable I want to display an error message explaining to set the owner of the directory to whoever the webserver is being run as (eg. www-data, nobody) but as most people don't know this it would be nice to be able to tell them who to chown the directory to. Is it possible to find this from PHP?
A:
If you can run some bash, you can use whoami
or you might be able to poke around in /proc
BCS
2009-05-05 23:09:19
A:
The quick-and-dirty trick I use is to write a file to /tmp/
. It should be created with the user and group used by the PHP process.
Ben Blank
2009-05-05 23:11:49
A:
That error message falls apart in a windows server environment. "Please make sure the web server has write access to the directory" is probably a better error message.
gnarf
2009-05-05 23:13:28
+1
A:
If on linux/unix:
<?php
$temp = tmpfile();
print_r(posix_getpwuid(fileowner($temp)));
?>
Jordan S. Jones
2009-05-05 23:13:35