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

很长时间没有写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"  ); 搞定了,哎要是换成以前肯定一下就想到了。

时间: 2024-11-05 14:51:14

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

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 /Library/WebServer/Documents/test.php on line 22错误,提示未开启权限 解决办法:在终端输入 sudo chown -R _www:_www 文件路径(例如: sudo chown -R _www:_www /Library/WebServer/Docu

“file_put_contents () failed to open stream: Permission denied” 解决办法

访问"www.***.com/admin/index/index" :的时候, 会出现错误如下: 报错为: failed to open stream: Permission denied --- 无法打开流:权限被拒绝 没权限访问 解密时刻: 切换到该目录 cd /PHP/admin/tp5/ chmod -R 777 runtime 就这样完美解决了! 原文地址:https://www.cnblogs.com/JiangDakang/p/9566327.html

thinkphp5访问报错 ...with message 'mkdir(): Permission denied' in... 或...failed to open stream: Permission denied' in...

报错截图1: 报错截图2: 报错原因没有权限访问thinkphp5/runtime目录. 解决方法: 1.如果thinkphp5/runtime目录下面有文件,先清空thinkphp5/runtime目录: 2.修改thinkphp5/runtime目录权限为可读可写. thinkphp5访问报错 ...with message 'mkdir(): Permission denied' in... 或...failed to open stream: Permission denied' in.

PHP "Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0" 错误

遇到这个问题,研究了很久,结果发现上传的文件的全部没有读权限 不只是文件夹,上传的文件也要至少添加+444的权限,也就是读的权限 Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required '/mnt/yun0/api/login.php' (include_path='.:/opt/lampp/lib/p

failed to open stream: Permission denied in

最近在做一个Web2.0的项目,需要用到XML作为数据库来处理数据,然后我用php写的,结果就是出现了这个错误!快把我搞疯了啊!!! 后来我想,其实就是权限不足,但是我认为那个eclipse[我使用eclipse开发]的workspace我给了777的权限啊,怎么会有这种情况呢?没办法,只得烦自己之前的工作记录,然后问题就来了,我在终端输入的命令是 sudo chmod 777 /home/***/Documents/workspace 所以在它下面依旧有文件不能读取和写入 那么怎么办呢? 很简

laravel错误处理...app/storage/sessions...failed to open stream: Permission denied

方法:到laravel跟目录下执行如下操作: 1)php artisan cache:clear 2)chmod -R 777 app/storage 3)php artisan dump-autoload 版权声明:本文为博主原创文章,未经博主允许不得转载.

如果Laravel 报错 file_put_contents(): failed to open stream

问题解决方法 执行命令 php artisan cache:clear 并赋予 /storage 文件夹读写权限: chmod -R 777 storage: 若在执行 php artisan cache:clear 时出现错误:Uncaught UnexpectedValueException: The stream or file "/storage/logs/laravel.log" could not be opened: failed to open stream: Perm

kvm错误:failed to initialize KVM: Permission denied

错误1: 启动kvm容器报错: # virsh start hadoop-test error: Failed to start domain hadoop-testerror: internal error: process exited while connecting to monitor: Could not access KVM kernel module: Permission deniedfailed to initialize KVM: Permission denied 解决:

git添加遇到问题 sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey).

sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey). 参考 https://help.github.com/cn/github/authenticating-to-github/error-permission-denied-publickey https://segmentfault.com/a/1190000008733238 https://www.cnblo