[记录]关于PHP中file_put_contents()的路径不能使用变量代替的解决 | 祭夜博客
  • 欢迎光临,这个博客颜色有点多

[记录]关于PHP中file_put_contents()的路径不能使用变量代替的解决

php msojocs 4年前 (2020-02-28) 3262次浏览 已收录 1个评论 扫描二维码
文章目录[隐藏]

前言(发生来源)

看到群友“老陈”发出冒泡商城的图片时,我想到能不能批量获取MRP应用,于是在一番抓包测试之后,脚本基本完成,

但是,在使用file_put_contents() 保存文件的时候,遇到了问题。

[记录]关于PHP中file_put_contents()的路径不能使用变量代替的解决

详情

一开始之这么写的:

// 存储MRP文件
$filename = 'mrp/'.$filename;
file_put_contents($filename, $fileContent);

但是,出现奇怪的错误

Warning: file_put_contents() expects parameter 1 to be a valid path, string given in E:\Backup\backup document\WEB\test\index.php on line 51

所以,pathstring有什么区别????
一脸懵逼。。。遂搜索之。在stackoverflow找到如下帖子:
file_put_contents() expects parameter 1 to be a valid path, string given
I got the same error before but I don’t know if this solution of mine works on your problem you need to remove the “\0” try replace it:
$cleaned = strval(str_replace("\0", "", $buttons_first));

(我猜\0是在字符串结尾。。)试着改成这样:

// 存储MRP文件
$filename = strval(str_replace("\0", "", 'mrp/'.$filename));
file_put_contents($filename, $fileContent);

成了!
—–完—–


祭夜の咖啡馆 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:[记录]关于PHP中file_put_contents()的路径不能使用变量代替的解决
喜欢 (1)
[1690127128@qq.com]
分享 (0)
发表我的评论
取消评论
OwO表情
贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. 厉害,来学习下。
    哈灵游戏2020-03-06 13:31 回复 Mac OS X | Firefox浏览器 73.0