good morning 大佬们~
1.图片地址:http://aimg8.oss-cn-shanghai.aliyuncs.com/crm_code_img/qrcode?t=10804154
2.代码模块PHP实现只能保存一个临时文件夹然后去下载文件。
3.哪位大神可以耐心解答或者给出解决方案。
这是我测试成功之后的,下载后的文件我默认在和你代码运行的地方同一级,记得给你要写入图片的目录写入权限
<?php
function test()
{
$url = 'http://aimg8.oss-cn-shanghai.aliyuncs.com/crm_code_img/qrcode?t=10804154';
$header = array("Connection: Keep-Alive", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3", "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$content = curl_exec($ch);
$curlinfo = curl_getinfo($ch);
//关闭连接
curl_close($ch);
if ($curlinfo['http_code'] == 200) {
if ($curlinfo['content_type'] == 'image/jpeg') {
$exf = '.jpg';
} else if ($curlinfo['content_type'] == 'image/png') {
$exf = '.png';
} else if ($curlinfo['content_type'] == 'image/gif') {
$exf = '.gif';
}
$filename = date("Y-m-d") . uniqid() . $exf;//这里默认是当前文件夹,可以加路径的 可以改为$filepath = '../'.$filename
$res = file_put_contents($filename, $content);//同样这里就可以改为$res = file_put_contents($filepath, $content);
}
}
test();
?>