在使用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. Centos rpm缺少依赖无法安装mysql5.5

    rpm -ivh mysql-5.5.22-2.1.i386.rpm --nodeps --force 缺少依赖导致rpm -ivh mysql-5.5.22-2.1.i386.rpm命令无法安装!

  2. Redis的入门Demo(java)

    java代码部分参考了:http://www.runoob.com/redis/redis-java.html 在java中使用Redis,需要引入Redis驱动,就是jedis-2.1.0.jar, ...

  3. IntelliJ IDEA中创建并运行scala应用程序

    1.安装scala插件 2.创建scala项目 下载scala SDK,如果你已经下载了,选择你所下载的版本,点击OK

  4. HDU 2852 KiKi's K-Number

    权值线段树 #include <cstdio> #include <cstring> const int N=200000,M=220000; int k,q,x,y,sum[ ...

  5. PHP程序猿必须学习的第二课——站点安全问题预防

    作为PHP程序猿.第一课我们学习了基本的语法.那么在熟悉基本的语法之后我们应该学些什么呢?我觉得是安全问题.安全问题基于一个站点宛如基石,一着不慎,意味着灾难性的事故. 这里主要就提三点最简单,也是最 ...

  6. Android多线程及异步处理问题

    1.问题提出 1)为何需要多线程? 2)多线程如何实现? 3)多线程机制的核心是啥? 4)到底有多少种实现方式? 2.问题分析 1)究其为啥需要多线程的本质就是异步处理,直观一点说就是不要让用户感觉到 ...

  7. HTML5+CSS3正式开课

    HTML5+CSS3 HTML5+CSS3 HTML5+CSS3

  8. C# inherit

    Case:class A has a construct. class B is inherit from class A and B also has a construct. What's the ...

  9. ;(function($,window,undefined){})(jQuery,window)详细解析————借助B5教程解析自己整理了一下

    在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...

  10. dedecms的入门使用

    前段时间(其实也很远了)一直在学习dedecms,这里对前段时间的学习做一个总结. dedecms学习网址:http://help.dedecms.com/v53