I met a php issue when uploading folder or files on the xampp's apache of ubuntu server:
I created a specify FTP group and user with the folder:
Group:User = ABC:abc_user the root folder of the group = /htdocs/ABC/uploads
Put the program to the folder:
/htdocs/ABC/upload.php
And chown-ed:
sudo chown -R abc_user:ABC /htdocs/ABC
The main program will upload the create sub-folders and files on the /uploads:
function create_folders($dir) {
return is_dir($dir) or ( create_folders(dirname($dir)) and mkdir($dir));
}
move_uploaded_file($tmp_filename, $fileLocation)
The program works and can be uploaded the folders and files :).
However, I found the folders and files, they are under the group:user(1:1).
I tried google the solutions and run some script to do self-test.
Added a test.php on the folder and chown-ed again:
echo exec("who");
chgrp($path,$group_name);
chown($path, $user_name);
Got the result:
daemon
Warning: chgrp(): Operation not permitted in test.php
Warning: chown(): Operation not permitted in test.php
Array (
[name] => daemon
[passwd] => x
[uid] => 1
[gid] => 1
[gecos] => daemon
[dir] => /usr/sbin
[shell] => /usr/sbin/nologin
)
I was confused why it was 'daemon' and group:user was 1:1, not my group:user.
So I tried in another way to seek any things in the server side, the xampp setting part,
and found out a some kind of things on the httpd.conf:
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
</IfModule>
Then I tried to change group:user:
<IfModule unixd_module>
User abc_user
Group ABC
</IfModule>
Finally,I uploaded again and the group:user under the ABC:abc_user!!!!
But.....There was a problems that XAMPP said it cannot not save session if I'm using session for some programs :(....
<br />\n<b>Warning</b>: session_start(): open(/opt/lampp/temp//sess_9k3dm9uv2gcgof1c37eacjlv36, O_RDWR)
failed: Permission denied (13) in <b>/opt/lampp/htdocs/upload.php</b> on line <b>1</b><br />\n
<b>Warning</b>: Unknown: open(/opt/lampp/temp//sess_9k3dm9uv2gcgof1c37eacjlv36, O_RDWR)
failed: Permission denied (13) in <b>Unknown</b> on line <b>0</b><br />\n<br />\n
<b>Warning</b>: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/opt/lampp/temp/) in <b>Unknown</b> on line <b>0</b><br />\n
It sounds I need to change the path of temp to /htdocs/ABC/temp then it should work,but it looks weird.
Any talent have good idea? :)
Thanks & Regards.