使用简单文件上传脚本时出现PHP错误:无法打开流:没有此类文件或目录

问题描述 投票:1回答:4

我是一个PHP n00b但按照这个优秀的tut说明:

PHP Tizag file upload tutorial

然而,虽然这在我运行默认内置Apache的Mac(OSX 10.8)上运行良好,但它失败了,并且在CentOS 6机箱上不起作用。浏览Apache日志,我得到了这个:

failed to open stream: No such file or directory

在“uploads”文件夹中的权限已设置为777,该文件夹位于/ var / www / html的根目录中(在Mac上它/ Library / Webserver / Documents)

[Tue Apr 30 13:05:11 2013] [error] [client (My IP Address)] PHP Warning:  move_uploaded_file(uploads/Today notes.txt): failed to open stream: No such file or directory in /var/www/html/test/uploads3.php on line 8, referer: ht*p://serverip.myserver.com/test/form4.html

[Tue Apr 30 13:05:11 2013] [error] [client (my IP address)] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpc8AGo8' to 'uploads/Today notes.txt' in /var/www/html/test/uploads3.php on line 8, referer: ht*p://serverip.myserver.com/test/form4.html

我错过了PHP或Apache中的一些设置以使其正常工作吗?

提前谢谢了。

php apache centos
4个回答
1
投票

根据你的问题,uploads文件夹在/var/www/html,但是它正在尝试上传到不存在的/var/www/html/test/uploads的错误消息

您需要修复代码以上载到正确的路径,或者您需要在测试目录中创建uploads目录


0
投票

请参阅操作系统的文档。 CentOS 6具有额外的安全配置,可能会阻止PHP访问tmp文件夹。

允许该文件夹访问Apache HTTPD(或将临时上载路径更改为允许Apache HTTPD通过SELinux配置访问的文件夹)。还要审核SELinux日志以找出确切阻止访问目录的设置。

例如。如果您没有将PHP作为Apache模块运行,则可能需要允许其他进程(例如PHP(F)CGI二进制文件)受保护的文件系统资源。


0
投票

希望这能解决您的问题

首先检查文件夹是否存在,如果不是如下所示

if(!is_dir('uploads/Today')){
   mkdir("uploads/Today", 0755);
}

0
投票

我知道这是一个很老的帖子,但是和很多人一样,人们对这个问题没有任何建议。但是,我记得几年前我遇到的问题,最终它也影响了这种情况。

问题是SELinux,你必须配置它允许读/写:Centos 7 / Apache / PHP - mkdir(): Permission denied

解:

chcon -R -t httpd_sys_content_t / var / www /

chcon -R -t httpd_sys_content_rw_t / var / www / html /

如果所有其他方法都失败了,请尝试此解决方案。

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.