在使用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

参考资料:

StackOverflow1

StackOverflow2

[置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)的更多相关文章

  1. file_put_contents() failed to open stream: Permission denied 问题解决

    很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能. function downloadFile( $url , $savePath = '' ) {     $fileName = ge ...

  2. 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 ...

  3. php上传文件时出现错误:failed to open stream: Permission denied

    尝试使用php写了一段小的上传程序,但是在使用的时候,在上传文件时出现这个错误,由于之前在写程序要读文件,曾经出现过这个问题,当时是因为要读的文件的权限不够,于是使用chmod 775 1.txt把文 ...

  4. 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 ...

  5. file_put_contents () failed to open stream: Permission denied 解决办法

    今天,帮朋友配置服务器thinkphp5的时候,直接访问“www.***.com/admin/index/index” : 出现以下错误: file_put_contents (/PHP/admin/ ...

  6. failed to open stream: Permission denied in警告错误

    问题是文件所在目录的权限问题导致的.只需要将警告文件所在的目录权限更改为777(至少是006)即可 例如 (...a.log)failed to open stream: Permission den ...

  7. 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 ...

  8. 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 ...

  9. docker 错误failed to open stream: Permission denied 解决方法

    在服务器上面.运行docker时,php目录会发生权限问题解决方法如下: 1:进入php目录下面 docker exec -ti php56 /bin/bash #进入php容器 chown -R w ...

随机推荐

  1. Lucence.net索引技术 一

    1.建立索引 为了对文档进行索引,Lucene 提供了五个基础的类,他们分别是 Document, Field, IndexWriter, Analyzer, Directory.下面我们分别介绍一下 ...

  2. C语言(1)--准备

    经过很长一段时间的准备,终于重新弄懂了一些C语言的问题,再次熟悉了C语言的大致应用,对此略有体会,在此以博客记录于此! 准备工作: 运行平台:Linux 编辑工具:vim (还可以使用emac,ged ...

  3. ReactiveCocoa学习资料

    ReactiveCocoa 学习资料: ReactiveCocoa入门教程:第一部分 http://www.cocoachina.com/ios/20150123/10994.html Reactiv ...

  4. w3c标准的selection对象介绍

    简介 术语 属性 方法 document.activeElement document.designMode = 'on'; 简介 selection是对当前激活选中区(即高亮文本)进行操作. 在非I ...

  5. Qt的目录依赖问题----怎样生成一个绿色的Qt软件包

    Qt的目录依赖问题----怎样生成一个绿色的Qt软件包 一.核心问题: 如果将编译好的Qt文件拷贝到任何目录下,作为一个绿色软件库来使用? 二.原理讨论 由于Qt在编译的时候将安装路径硬编码到了库文件 ...

  6. JavaEE Tutorials (11) - 使用Criteria API创建查询

    11.1Criteria和Metamodel API概述16811.2使用Metamodel API为实体类建模170 11.2.1使用元模型类17011.3使用Criteria API和Metamo ...

  7. android LinearLayout和RelativeLayout实现精确布局

    先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin  :是控件边缘相对父空间的边距 ...

  8. C++_template_栈的链式存储及实现

    由于在C++数据结构中的代码不完整,特补全.等日后当工程库调用. 若有疑问,请留言. #include<iostream> using namespace std; template< ...

  9. vs2013 linq to mysql

    安装文件 1.下载安装文件 2.创建项目 3.创建mysql数据连接 4.新建ADO.NET数据模型 项目实现代码 using (WorkerContainer db = new WorkerCont ...

  10. HDU 4705 Y

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submis ...