很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能。

function downloadFile( $url , $savePath = '' )
{
    $fileName = getUrlFileExt( $url );
    $fileName = rand(0,1000). '.' . $fileName ;
    $file = file_get_contents ( $url );
    file_put_contents ( $savePath . '/' . $fileName , $file );
    return $fileName ;
}

调用downloadFile(  "http://www.xxx.com"  ,  "/bak"  );

怎么都不行,一直提示file_put_contents() failed to open stream: Permission denied

后面把文件夹权限也加上还是不行,郁闷了。

最后突然想到地址不应该是相对的哦。

改为downloadFile(  "http://www.xxx.com"  ,  rtrim($_SERVER['DOCUMENT_ROOT'],'/')."/bak"  ); 搞定了,哎要是换成以前肯定一下就想到了。

file_put_contents() failed to open stream: Permission denied 问题解决的更多相关文章

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

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

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

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

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

  4. [置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)

    在使用PHP上传文件之后,我们有时候还需要移动到特定的文件夹,这时候就要调用move_uploaded_file()函数,可是会出现如下错误: Warning: move_uploaded_file( ...

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

  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. docker 错误failed to open stream: Permission denied 解决方法

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

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

随机推荐

  1. CentOS升级git

    1.首先查看下当前的版本 [root@localhost ~]# git --versiongit version 1.8.2.1 2.尝试进行升级 [root@localhost ~]# yum u ...

  2. android 自动调整屏幕分辨率

    请看 http://blog.csdn.net/awp258/article/details/7593340

  3. bzoj1858: [Scoi2010]序列操作

    lazy-tag线段树. #include<cstdio> #include<algorithm> #include<cstring> using namespac ...

  4. JS 打印报表

    <script type="text/javascript"> window.print(); </script> 前台页面: <%@ Page La ...

  5. easyui资源

    官网地址:http://www.jeasyui.com/index.php(相关文档示例,有demo, tutorial, documentation) 未混淆的源码:http://jquery-ea ...

  6. Windows安装weblogic

    WebLogic安装结束 以下是进入MyEclipse启动配置WebLogic

  7. 【转】Git详解之一:Git起步

    原文网址:http://blog.jobbole.com/25775/ 原文:<Pro Git> 起步 本章介绍开始使用 Git 前的相关知识.我们会先了解一些版本控制工具的历史背景,然后 ...

  8. 【转】报错:Program "sh" not found in PATH

    原文网址:http://www.cnblogs.com/SadNight/p/3406201.html (1) 报错:Program "sh" not found in PATH ...

  9. Kernel 中的 GPIO 定义和控制

    最近要深一步用到GPIO口控制,写个博客记录下Kernel层的GPIO学习过程! 一.概念 General Purpose Input Output (通用输入/输出)简称为GPIO,或 总线扩展器. ...

  10. C# 中类和结构的区别

    转角撞倒猪原文C# 中类和结构的区别