move_uploaded_file给人"未能打开流:权限被拒绝"所有的配置,我没有错误后, [英] move_uploaded_file gives "failed to open stream: Permission denied " error after all configurations i did

查看:896
本文介绍了move_uploaded_file给人"未能打开流:权限被拒绝"所有的配置,我没有错误后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到试图与Apache 2.2和PHP 5.3在CentOS配置上传目录时,此错误。

I keep getting this error when trying to configure the upload directory with Apache 2.2 and PHP 5.3 on CentOS.

在php.ini中:

upload_tmp_dir = /var/www/html/mysite/tmp_file_upload/

在httpd.conf文件:

In httpd.conf:

Directory /var/www/html/mysite/tmp_file_upload/>
    Options  -Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory /var/www/html/mysite/images/>
                Options -Indexes
</Directory>

CentOS的目录权限:

CentOS directory permissions:


drwxrwxr-x 2 root root 4096 Nov 11 10:01 images
drwxr-xr-x 2 root root 4096 Nov 12 04:54 tmp_file_upload

不管我做什么,当我上传的文件我不断收到来自PHP这个错误:

No matter what I do, I keep getting this error from PHP when I upload the file:

警告:move_uploaded_file(图片/ robot.jpg):未能打开流:权限在/var/www/html/mysite/process.php否认线78

Warning: move_uploaded_file(images/robot.jpg): failed to open stream: Permission denied in /var/www/html/mysite/process.php on line 78

警告:move_uploaded_file()以:无法'的/ tmp / phpsKD2Qm在/var/www/html/mysite/process.php移动到图像/ robot.jpg在线78

Warning: move_uploaded_file(): Unable to move '/tmp/phpsKD2Qm' to 'images/robot.jpg' in /var/www/html/mysite/process.php on line 78

正如你可以看到它从来没有作出关于上传文件从php.ini文件中的配置。

As you can see it never did take the configuration from the php.ini file regarding the upload file.

我在做什么错在这里?

推荐答案

这是因为图片 tmp_file_upload 是只有用户写入。对于上传的工作,我们需要做相同的httpd进程所有者这些文件夹的所有者或使它们在全球可写(糟糕的做法)。

This is because images and tmp_file_upload are only writable by root user. For upload to work we need to make the owner of those folders same as httpd process owner OR make them globally writable (bad practice).


  1. 检查Apache进程所有者: $的ps aux | grep的的httpd 。第一列将是典型的车主将被

  2. 修改图像的所有者 tmp_file_upload 将成为或你在步骤1中,找到了失主

  1. Check apache process owner: $ps aux | grep httpd. The first column will be the owner typically it will be nobody
  2. Change the owner of images and tmp_file_upload to be become nobody or whatever the owner you found in step 1.

$ sudo的CHOWN没有人在/ var / www / html等/ mysite的/图像/

$ sudo的CHOWN没有人在/ var / www / html等/ mysite的/ tmp_file_upload /

CHMOD 图片 tmp_file_upload 现在是由业主可写的,如果需要的话[好像你已经有这样的地方。提到@Dmitry Teplyakov答案。

Chmod images and tmp_file_upload now to be writable by the owner, if needed [Seems you already have this in place]. Mentioned in @Dmitry Teplyakov answer.

$ sudo的搭配chmod -R 0755的/ var / www / html等/ mysite的/图像/

$ sudo的搭配chmod -R 0755的/ var / www / html等/ mysite的/ tmp_file_upload /

有关详细信息,为什么这种行为happend,查手册<一个href=\"http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir\">http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir请注意,它也谈的open_basedir 指令。

For more details why this behavior happend, check the manual http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir , note that it also talking about open_basedir directive.

这篇关于move_uploaded_file给人&QUOT;未能打开流:权限被拒绝&QUOT;所有的配置,我没有错误后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆