Reputation: 1902
I have an simple PHP script that creates a folder and then copies certain files into it. The folder (and copied files) have all 755 permissions. The problem is, it sets the user as Apache. Now I can not delete or change permissions through FTP. I can only 'reset ownership' in my DirectAdmin. There I can see the user changes from "Apache" to "matthdc58".
How can I let PHP create a folder with "matthdc58" as user? I tried chown()
- failed:
Warning: chown() [function.chown]: Operation not permitted in /home/matthdc58/domains/hiddendomain.com/public_html/Home.php on line 78
Warning: chown() [function.chown]: Operation not permitted in /home/matthdc58/domains/hiddendomain.com/public_html/Home.php on line 79
Warning: chown() [function.chown]: Operation not permitted in /home/matthdc58/domains/hiddendomain.com/public_html/Home.php on line 80
Warning: Cannot modify header information - headers already sent by (output started at /home/matthdc58/domains/hiddendomain.com/public_html/Home.php:78) in /home/matthdc58/domains/hiddendomain.com/public_html/Home.php on line 90
I also tried (seemed to solve others' problems) php_flag safe_mode off
in my .htaccess, to no prevail.
My whole PHP script:
$dirtocreate = 'userdata/'.$_SESSION['uname'];
$oldumask = umask(0);
mkdir($dirtocreate, 0755);
umask($oldumask);
copy('img/100x100.png', $dirtocreate.'/100x100.png');
copy('img/64x64.png', $dirtocreate.'/64x64.png');
//Verify correct owner
chown($dirtocreate, 'matthdc58');
chown($dirtocreate.'/100x100.png', 'matthdc58');
chown($dirtocreate.'/64x64.png', 'matthdc58');
//Verify correct permissions, just to be sure
chmod($dirtocreate,0755);
chmod($dirtocreate.'/100x100.png',0755);
chmod($dirtocreate.'/64x64.png',0755);
So, just to clarify:
Upvotes: 0
Views: 1069
Reputation: 1902
It turned out to be related to the version of PHP I was using.
At recommendation of my host, Versio, I changed the version of PHP by adding
<FilesMatch "\.php$">
AddHandler x-httpd-php54 .php
</FilesMatch>
to my .htaccess file.
I don't think this is relevant for others, as this had to do with the rights, but you can always try.
Again, thanks to @LeSamAdmin for helping me out!
Upvotes: 0
Reputation: 246
Please check you have chmodded and chowned your directory: /home/matthdc58/domains/hiddendomain.com/public_html/ to your username. :)
Upvotes: 1