简体   繁体   English

创建上传目录的最安全方法是什么?

[英]What is the most secure way to create upload directories?

I have an image upload script. 我有一个图片上传脚本。 I ran into some trouble with permission errors so for the last little while the upload directory has had permissions 0777. Dangerous, I know. 我在权限错误方面遇到了一些麻烦,因此在最后一刻,上传目录的权限为0777。很危险,我知道。

For some reason, it was the only permission that would allow the files to upload. 由于某种原因,它是唯一允许文件上传的权限。 I have now realised that the reason a safer permission didn't work was because of the owner of the directory. 我现在意识到,更安全的权限不起作用的原因是目录的所有者。

I've been creating my upload directories using FTP. 我一直在使用FTP创建上传目录。 I thought this would be okay. 我以为可以。 But from what I understand FTP and HTTP aren't in the same group? 但是据我了解,FTP和HTTP不在同一个组中?

I've started creating the directories using PHPs mkdir() allows me to set a safer permission that works with my script. 我已经开始使用PHP创建目录mkdir()允许我设置与脚本兼容的更安全的权限。

But before I possibly get into another bad habit. 但是在我可能养成另一个坏习惯之前。 Can someone please confirm that this is the correct way to do it? 有人可以确认这是正确的方法吗? Is there a better way? 有没有更好的办法?

The owner of the directory should be the user which runs your PHP script - on Ubuntu this would be www-data . 目录的所有者应该是运行您的PHP脚本的用户-在Ubuntu上,这将是www-data Shortly, creating folders with PHP mkdir() is okay. 很快,可以使用PHP mkdir()创建文件夹。 Then you should set permissions. 然后,您应该设置权限。 0700 is the most secure but if other user needs to read from or write to this directory, you should add this user to the main group of user which runs your PHP script and set permissions to 0750 or 0770 respectively. 0700是最安全的,但是如果其他用户需要读取或写入此目录,则应将此用户添加到运行PHP脚本并将权限分别设置为07500770的主要用户组中。 On Ubuntu this group is also www-data . 在Ubuntu上,该组也是www-data

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

相关问题 在PHP中验证URL的最安全方法是什么? - What is the most secure way to validate URLs in PHP? 用PHP将图像文件上传到服务器的最安全方法是什么? - What is the most secure method to upload image file to server with PHP? 在PHP中设置管理区域最安全的方法是什么? - What is the most secure way to setup an admin area in PHP? 将ID从页面传递到另一个页面的最好/最安全的方法是什么? - What is the best/most secure way to pass an id from a page to another? 使用Facebook登录系统api的最安全方法是什么 - What's the most secure way to use facebook login system api 加密Ajax数据的最佳和最安全的方法是什么? - What is the best and most secure way to encrypt Ajax data? 允许管理员成为其他用户的最简单/最安全的方法是什么 - What is the easiest/most secure way to allow admins to become other users 在Linux中写入命名管道的最佳,最安全的方法是什么? - What is the best, most secure way to write to a named pipe in Linux? 什么是可以处理所有文件类型的最安全的php文件上传方法? - What is the Most Secure php file upload method that can handle all filetypes? 在没有数据库的情况下使用PHP加密密码的最安全方法是什么 - What's the most secure way to encrypt a password using PHP without a database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM