php Codeigniter – 上传目标文件夹似乎不可写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19433382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter – The upload destination folder does not appear to be writable
提问by anniebabannie
I'm using CodeIgniter's upload helper and received the above error when trying to upload an image. The permissions for the folder I'm trying to upload to are 755. When I changed it to 777, the error went away, but isn't 777 kind of a security risk?
我正在使用 CodeIgniter 的上传助手并在尝试上传图像时收到上述错误。我尝试上传到的文件夹的权限是 755。当我将其更改为 777 时,错误消失了,但 777 不是一种安全风险吗?
I'm running on Apache. Is there a better way to allow users to upload files without setting the folder permissions to 777? How can I get 755 to work?
我在 Apache 上运行。有没有更好的方法允许用户上传文件而不将文件夹权限设置为 777?我怎样才能让 755 工作?
Thanks for the help!
谢谢您的帮助!
回答by Cristian Bitoi
If the folder is for loading files by users than permisision 777 is required.
如果文件夹供用户加载文件,则需要 777 权限。
It's up to you to validate what files are loadedthrough upload script. Also you can use .htaccess to alow or not alow certain files to be executed from that directory.
由您来验证通过上传脚本加载了哪些文件。您也可以使用 .htaccess 来允许或不允许从该目录执行某些文件。
The documentation for upload in codeigniter it's pretty simple and intuitive. Also here you can look at some ways to validate the type of files that are uploaded https://codeigniter.com/userguide3/libraries/file_uploading.html
在 codeigniter 中上传的文档非常简单直观。您也可以在这里查看一些方法来验证上传的文件类型https://codeigniter.com/userguide3/libraries/file_uploading.html
回答by user6025879
In my NGINX + PHP-FPMinstallation the issue was solved changing the SElinux parameters from enforcing
to permissive
:
在我的NGINX + PHP-FPM安装中,将 SElinux 参数从更改enforcing
为permissive
:
edit and change options with vi /etc/selinux/config
apply options without restart with sudo setenforce 0
check the status with sestatus
.
使用vi /etc/selinux/config
应用选项编辑和更改选项 而无需重新启动并sudo setenforce 0
使用sestatus
.
回答by Vinie
I don't think so giving any folder on server 777 permission is good. Instead giving 777 permission i suggest make www-data user as owner of desired folder like below
我认为在服务器 777 上授予任何文件夹的权限都不好。而不是给予 777 权限,我建议让 www-data 用户作为所需文件夹的所有者,如下所示
chown -R www-data:www-data /var/www/html/uploads/
回答by Anand
try this:
尝试这个:
sudo chmod 777 -R /path/to/write/folder
须藤 chmod 777 -R /path/to/write/folder
回答by Kyle Coots
I know this is not an active question and may not be an issue for most but because I came across this I wanted to clarify for anyone else that may see this.
我知道这不是一个活跃的问题,对大多数人来说可能不是问题,但是因为我遇到了这个问题,所以我想向其他可能看到这一点的人澄清一下。
You DO NOT need 777 permission on your upload directory. This is actually not a good idea. The last 7 means it is public writable which does not need to be in most cases. Typically 755 should be good enough
您的上传目录不需要 777 权限。这实际上不是一个好主意。最后 7 表示它是公共可写的,在大多数情况下不需要。通常 755 应该足够好
More than likely the issue is that the directory is not owned but the user running Apache which is typically www-data
问题很可能是该目录不属于该目录,而是运行 Apache 的用户通常是 www-data
Step by step:
一步步:
Check owner of dir (i.e.)
检查目录的所有者(即)
ls -l /path/to/upload/
Output should show similar
输出应显示类似
drwxr-xr-x 4 www-data www-data 4096 Oct 26 20:41 uploads
If not then you should change to www-data if that is the user Apache is running under. To check what user apache is running under :
如果不是,那么您应该更改为 www-data 如果这是运行 Apache 的用户。要检查 apache 正在运行的用户:
ps aux | egrep '(apache|httpd)'
This should list something similar:
这应该列出类似的内容:
www-data 419 0.0 0.9 556292 156656 ? S 18:46 0:00 /usr/sbin/apache2 -k start
Hope This Helps!
希望这可以帮助!