On some hosts I use, when PHP creates a file, it creates it as owned by the FTP user (which is how I like it), but on other hosts it is created as being owned by Apache or nobody or some other user. Is there are function to work out what the setting is? So I could do something like: if (is_ftp_user()){ // Create some files, directories etc. } else { // Prompt to upload files, directories by FTP } Code (markup):
Usually, if php is run via CGI it will run as the user. If apache, it will run under nobody or apache.
Running PHP as user also often done with suPHP. You can try to get current user under *nix using whoami command via backticks or shell_exec function (could be disabled in safe mode etc.): <? echo 'whoami: '.`whoami`; ?> PHP:
Thanks, I ended up using code like the following: $phpRunsAs = trim(`whoami`); $thisFileOwner = posix_getpwuid(fileowner('/path/to/thisfile.php')); if ($phpRunsAs != $thisFileOwner['name']){ // Make directories etc. } else { // Don't do the stuff, but echo a notice to the user to do it in FTP } PHP: