如何使用所有者组和用户更改 php 上传
How to change the php upload with owner group and user
我在 ubuntu 服务器的 xampp 的 Apache 上上传文件夹或文件时遇到 php 问题:
我使用以下文件夹创建了一个指定的 FTP 组和用户:
Group:User = ABC:abc_user
the root folder of the group = /htdocs/ABC/uploads
将程序放入文件夹:
/htdocs/ABC/upload.php
和 chown-ed:
sudo chown -R abc_user:ABC /htdocs/ABC
主程序会上传创建的子文件夹和文件到/uploads:
function create_folders($dir) {
return is_dir($dir) or ( create_folders(dirname($dir)) and mkdir($dir));
}
move_uploaded_file($tmp_filename, $fileLocation)
程序运行正常,可以上传文件夹和文件:)。
但是,我找到了文件夹和文件,它们在 group:user(1:1).
下
我尝试了 google 解决方案和 运行 一些脚本来进行自检。
在文件夹上添加了 test.php 并再次 chown-ed:
echo exec("who");
chgrp($path,$group_name);
chown($path, $user_name);
得到结果:
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
)
我很困惑为什么它是 'daemon' 而 group:user 是 1:1,而不是我的 group:user.
所以我尝试用另一种方式在服务器端寻找任何东西,xampp设置部分,
并在 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>
然后我尝试改group:user:
<IfModule unixd_module>
User abc_user
Group ABC
</IfModule>
终于,我又上传了ABC:abc_user下的group:user!!!!
但是.....有一个问题,XAMPP 说如果我在某些程序中使用会话,它不能不保存会话:(....
<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.
有大佬有什么好办法吗? :)
感谢和问候。
我在 ubuntu 服务器的 xampp 的 Apache 上上传文件夹或文件时遇到 php 问题:
我使用以下文件夹创建了一个指定的 FTP 组和用户:
Group:User = ABC:abc_user the root folder of the group = /htdocs/ABC/uploads
将程序放入文件夹:
/htdocs/ABC/upload.php
和 chown-ed:
sudo chown -R abc_user:ABC /htdocs/ABC
主程序会上传创建的子文件夹和文件到/uploads:
function create_folders($dir) {
return is_dir($dir) or ( create_folders(dirname($dir)) and mkdir($dir));
}
move_uploaded_file($tmp_filename, $fileLocation)
程序运行正常,可以上传文件夹和文件:)。
但是,我找到了文件夹和文件,它们在 group:user(1:1).
下我尝试了 google 解决方案和 运行 一些脚本来进行自检。
在文件夹上添加了 test.php 并再次 chown-ed:
echo exec("who");
chgrp($path,$group_name);
chown($path, $user_name);
得到结果:
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
)
我很困惑为什么它是 'daemon' 而 group:user 是 1:1,而不是我的 group:user.
所以我尝试用另一种方式在服务器端寻找任何东西,xampp设置部分,
并在 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>
然后我尝试改group:user:
<IfModule unixd_module>
User abc_user
Group ABC
</IfModule>
终于,我又上传了ABC:abc_user下的group:user!!!!
但是.....有一个问题,XAMPP 说如果我在某些程序中使用会话,它不能不保存会话:(....
<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.
有大佬有什么好办法吗? :)
感谢和问候。