Need help with mkdir

Hey everyone!

I need some help with mkdir in my .php file. It’s not creating the directory.

I’m currently running Centos 6.6 web server, I have all folders chmod 755 and owner = Apache.

My code is as follows:
[php]<?php $chars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”;
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir("…/userdata/profile_pics/".$rand_dir_name);
?>[/php]

No error messages are shown and I’m 100% sure that the path /userdata/profile_pics exists.

Any help?

Is this on a VPS/ dedicated server? My guess is ‘Apache’ does not have permission to create the dir.

Try,

[php]
if( mkdir($path, 777) )
echo “directory created”;
else
echo “mkdir failed”;
[/php]

You need to us umask. Here is a bit of code I grabbed from an app I developed. Try this link for an explanation: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

[php]// unmask makes it so permissions will actually be set to what you want
if (!file_exists($image_path))
{
$old = umask(0);
mkdir($image_path, 0777);
umask($old);
}
if (!file_exists($thumb_path))
{
$old = umask(0);
mkdir($thumb_path, 0777);
umask($old);
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service