简体   繁体   English

PHP-向用户授予对ubuntu中root拥有的文件的权限

[英]PHP - Grant a user permissions to file owned by root in ubuntu

I am using Jasperreports for generating the reports. 我正在使用Jasperreports生成报告。 When I am generating the new reports it will be own by root with permission of 644 . 当我生成新报告时,将由root拥有644的权限。 So other users dont have permission to view this report.I want to change the ownership of the file or change the permission.So everyone can view or download the reports. 因此其他用户没有查看此报告的权限。我想更改文件的所有权或更改权限。这样每个人都可以查看或下载报告。

I tried below php functions 我尝试了以下php函数

chmod($item, 0777);   

chown($path, 'www-data');

It gives 它给

error: dont have permission to do this 错误:没有权限执行此操作

. Because its own by root and current user is www-data. 因为它的根用户和当前用户都是www-data。 Anyone please help me, 有人请帮我

Actually, based on what you're saying, all users have permissions to view that file. 实际上,根据您的发言,所有用户都有权查看该文件。 644 means owner can read and write, and group and others can only read. 644表示所有者可以读写,而组和其他人只能读取。 If your script is getting an error reading that file, it might be because of the permissions of the directories in is path, but not the file itself. 如果您的脚本在读取该文件时出错,则可能是由于is路径中目录的权限,而不是文件本身。

If you could change the owner or permissions of a file owned by root like that, it would subvert the whole concept of unix file permissions. 如果您可以像这样更改root拥有的文件的所有者或权限,那么它将破坏Unix文件权限的整个概念。 Think about it. 想一想。

You can always change the user running these reports though, or add logic on the report generation side to move or change the permissions on the file as the user who owns it. 但是,您始终可以更改运行这些报表的用户,或者在报表生成侧添加逻辑以作为拥有文件的用户移动或更改文件的权限。

As an aside, chmod 777 is an ugly kludge used only by those who have little knowledge of unix permissions . 顺便说一句,chmod 777是仅由对unix权限了解甚少的人使用的丑陋kludge。 Professionals don't do it. 专业人士不这样做。 You should bump your understanding of unix file permissions to the next level: https://www.tutorialspoint.com/unix/unix-file-permission.htm looks promising. 您应该将对Unix文件权限的了解提高到一个新的水平: https : //www.tutorialspoint.com/unix/unix-file-permission.htm看起来很有希望。

According to the manual, the owner and the supersuer have the right to do this. 根据手册,所有者和超级卖方有权这样做。

And you only chage the file mod or owner, will not do. 而且您只修改文件mod或所有者,不会这样做。 You have also to change the path. 您还必须更改路径。

chown wn

Attempts to change the owner of the file filename to user user. 尝试将文件文件名的所有者更改为用户user。 Only the superuser may change the owner of a file. 只有超级用户可以更改文件的所有者。

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem. 注意:该功能不适用于远程文件,因为必须通过服务器的文件系统访问要检查的文件。

Note: When safe mode is enabled, PHP checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed. 注意:启用安全模式后,PHP会检查正在操作的文件或目录是否与正在执行的脚本具有相同的UID(所有者)。

chmod chmod

Attempts to change the mode of the specified file to that given in mode. 尝试将指定文件的模式更改为mode中给定的模式。 Note: The current user is the user under which PHP runs. 注意:当前用户是运行PHP的用户。 It is probably not the same user you use for normal shell or FTP access. 您可能不是用于普通Shell或FTP访问的用户。 The mode can be changed only by user who owns the file on most systems. 在大多数系统上,只有拥有该文件的用户才能更改该模式。

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem. 注意:该功能不适用于远程文件,因为必须通过服务器的文件系统访问要检查的文件。

Note: When safe mode is enabled, PHP checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed. 注意:启用安全模式后,PHP会检查您将要操作的文件或目录是否与正在执行的脚本具有相同的UID(所有者)。 In addition, you cannot set the SUID, SGID and sticky bits. 另外,您不能设置SUID,SGID和粘性位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM