[置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)
在使用PHP上传文件之后,我们有时候还需要移动到特定的文件夹,这时候就要调用move_uploaded_file()函数,可是会出现如下错误:
Warning: move_uploaded_file(/var/www/cloud/upload_files/temp.txt): failed to open stream: Permission denied in /var/www/cloud/upload.php on line 27
Warning: move_uploaded_file(): Unable to move '/tmp/phpNgjlXX' to '/var/www/cloud/upload_files/temp.txt' in /var/www/cloud/upload.php on line 27
这是因为没有在/var/www/cloud/upload_files/目录下创建文件的权限,需要修改该目录的权限。可以简单地改为777,但不是很安全,也可以参照stackoverflow上的解决方法,先找到Apache进程的所有者,可以按照参考资料获取(我没有获取到)或者运行新的PHP脚本。
<?php echo exec('whoami'); ?>
或者:
<?php echo getenv('APACHE_RUN_USER'); ?>
我获得的用户为www-data,该用户属于www-data组,然后修改目录的所有者
chown www-data /var/www/cloud/upload_files
然后修改目录的访问权限为755,即可以解决问题。
chmod 755 /var/www/cloud/upload_files
参考资料:
[置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)的更多相关文章
- file_put_contents() failed to open stream: Permission denied 问题解决
很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能. function downloadFile( $url , $savePath = '' ) { $fileName = ge ...
- Warning: file_put_contents(data.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/test.php on line 22
最近在学习PHP 在保存文件的时候报Warning: file_put_contents(data.txt): failed to open stream: Permission denied in ...
- php上传文件时出现错误:failed to open stream: Permission denied
尝试使用php写了一段小的上传程序,但是在使用的时候,在上传文件时出现这个错误,由于之前在写程序要读文件,曾经出现过这个问题,当时是因为要读的文件的权限不够,于是使用chmod 775 1.txt把文 ...
- easyhadoop:failed to open stream:Permission denied in /var/www/html/index.php
今天又重新部署了下easyhadoop,结果apache后台服务器报这个错误: [Fri Dec 13 10:32:41 2013] [notice] SIGHUP received. Attempt ...
- file_put_contents () failed to open stream: Permission denied 解决办法
今天,帮朋友配置服务器thinkphp5的时候,直接访问“www.***.com/admin/index/index” : 出现以下错误: file_put_contents (/PHP/admin/ ...
- failed to open stream: Permission denied in警告错误
问题是文件所在目录的权限问题导致的.只需要将警告文件所在的目录权限更改为777(至少是006)即可 例如 (...a.log)failed to open stream: Permission den ...
- laravel he stream or file "..laravel-2019-02-14.log" could not be opened: failed to open stream: Permission denied
错误:The stream or file "/var/www/jianshu/storage/logs/laravel-2019-02-14.log" could not be ...
- move_uploaded_file failed to open stream permission denied
Make sure that: IWPG_user, where user is a system user of the subscription who has rights to "R ...
- docker 错误failed to open stream: Permission denied 解决方法
在服务器上面.运行docker时,php目录会发生权限问题解决方法如下: 1:进入php目录下面 docker exec -ti php56 /bin/bash #进入php容器 chown -R w ...
随机推荐
- 5.6.3.8 fromCharCode()方法
String构造函数本身还有一个静态方法:fromCharCode().这个方法的任务是接收一或多个字符编码,然后将它们转换成一个字符.从本质上来看,这个方法与实例方法charCodeAt()执行的是 ...
- RAW模板开发--入口文件官方规范
每个人都有自己的习惯,为了RAW模板能进一步推广,使RAW模板的开发也更有条理,所以写了这个文章. 规范1格式: <?php /*RAW标记声明-start*/ /*RAW标记声明-over*/ ...
- excel读入数据库
POI3.9效率大幅度提高,支持xls以及xlsx. 首先需要POI的JAR包,MAVEN配置如下: <!-- excel start --> <dependency> < ...
- MVC-03 控制器(5)
八.动作过滤器 有时在运行Action之前或之后会需要运行一些逻辑运算,以及处理一些运行过程中所生成的异常状况,为了满足这个需求,ASP.NET MVC提供动作过滤器(Action Filter)来处 ...
- LintCode-子数组之和
题目描述: 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出 [-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. publ ...
- Mathematica
Mathematica是一款科学计算软件,很好地结合了数值和符号计算引擎.图形系统.编程语言.文本系统.和与其他应用程序的高级连接.很多功能在相应领域内处于世界领先地位,它也是使用最广泛的数学软件之一 ...
- json数据与字符串的相互转化
json转成string[需要引用json2.js文件]: var arr=[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}]; var str=JSON ...
- Hibernate 知识点复习
核心接口 1 Configuration接口负责配置并启动Hibernate,创建SessionFactory对象 2 SessionFactory接口负责初始化Hibernate.它充当数据存储 ...
- Just another Robbery(背包)
1079 - Just another Robbery PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...
- GDAL1.9.1 IN VS2008 C#中的编译及使用
下载gdal1.9.1到官网:http://www.gdal.org/ GDAL库的简洁.高效深受开发人员的喜爱,很多开源的GIS软件甚至是商业GIS软件都使用了这个库.GDAL使用C++,在Visu ...