This seems to be a common problem, but I can't seem to find the exact answer I'm looking for. I'm running XAMPP on OSX, and in my web app am trying to allow an admin to create a directory if none exists for a new year. So, under htdocs/mywebapp/images, if a directory doesn't exist for, say, 2012, then mkdir() and begin uploading files to that directory.
Running ls -l from the mywebapp directory shows that the images directory is created as
drwxr-xr-x 18 myusername admin 612 Feb 12 17:32 images
so the first thing I tried was
sudo chmod 0775 images
which didn't help. Looking at the httpd.config file shows that the user/group is defined as www:www so I tried changing the owner/group to that:
sudo chown www:www images
which results in, as expected:
drwxrwxr-x 18 _www _www 612 Feb 12 17:32 images
but, again, I get the Permission denied error. So, I'm at a loss as to what my next step is. The php code I'm using to get to this point is here:
$directory_self = dirname(__FILE__);
$base_image_path = $directory_self . '/images/'; // outputs "/Applications/XAMPP/xamppfiles/htdocs/mywebapp/images/"
$year = '2012';
$image_path = $base_image_path . $year . '/'; // outputs "/Applications/XAMPP/xamppfiles/htdocs/mywebapp/images/2012/"
if(!file_exists($image_path)){
mkdir($image_path, 0775);
}
Thanks for your help.
try to check real process owner:
$processUser = posix_getpwuid(posix_geteuid());
echo($processUser['name']);