今天,群里一位朋友在用“PHP做微信小程序敏感图片、内容检测接口”的时候,报错如下:
file_put_contents(https://dsx.cdzer.com/upload/ceshi/qrcode.png):failed to open stream: HTTP wrapper does not support writeable connections
中文翻译
file_put_contents(https://dsx.cdzer.com/upload/ceshi/qrcode.png):打开流失败:HTTP包装器不支持可写连接
原因:
file_put_contents() 不能通过URL网址往远程写入文件。
解决方法
既然知道了原因,解决起来就容易多了。最终他的代码如下:
最后:
再来说说我这位群朋友所踩过的坑,以及整个解决问题的思路:
他最初怀疑是权限的问题,结果他直接把权限设置为777,结果依然还是报错。
他最后群里找到了我,截图我看到他的代码有两个 file_put_contents() ,让他调试的时候:
第一个 file_put_contents() 正常。
第二个 file_put_contents() 报错。 说明这里有问题,最后我帮忙看了一下他这里具体的代码,他是这么写的,如下:
$filepath = 'https://dsx.cdzer.com/upload/ceshi/qrcode.png';
file_put_contents($filepath,$img);