简体   繁体   English

PHP。 / tmp下的上传临时文件的权限。 如何配置

[英]PHP. Permissions of upload temp file under /tmp . How to configure

In my PHP class i upload files and then scan them with antivirus. 在我的PHP类中,我上传文件,然后使用防病毒软件对其进行扫描。 Uploaded files are stored in /tmp with names like /tmp/phpRANDOM (allas usually) 上载的文件以/ tmp / phpRANDOM之类的名称存储在/ tmp中(通常是阿拉斯)

But when i pass this path to clamav server it returns "Access denied". 但是,当我将此路径传递给clamav服务器时,它将返回“拒绝访问”。 For other files (not in /tmp) all works fine. 对于其他文件(不在/ tmp中),一切正常。 The reason is that /tmp/php... files have permissions rw------ (read/write only by owner). 原因是/ tmp / php ...文件具有rw ------权限(仅所有者读取/写入)。 but clamav works as different user from apache/php . 但是clamav与apache / php的用户不同。

So, the question. 所以,这个问题。 How PHP decides which permissions to use for upload temp files? PHP如何确定用于上传临时文件的权限? How i can configure this? 我该如何配置呢? maybe this is some umask configured on a user level? 也许这是在用户级别配置的一些umask? If i want to have rw--r--r-- permissions for files in /tmp folder , are there any reasons not doing this (security)? 如果我想对/ tmp文件夹中的文件具有rw--r--r--权限,是否有任何理由不这样做(安全性)?

I have found the solution. 我找到了解决方案。 I just change permissions to files before posting them to clamav 我只是在将文件发布到clamav之前更改文件的权限

It is like 它像是

$perm = fileperms($filepath) | 0644;
chmod($filepath, $perm);

And it works fine 而且效果很好

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

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