PHP如何通过URL实现图片下载操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计86个文字,预计阅读时间需要1分钟。
phpfunction imagefromURL($image, $rename) { $ch=curl_init($image); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $rawdata=curl_exec($ch); curl_close($ch); $fp=fopen($rename, wb);}
function imagefromURL($image,$rename)
{
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("$rename",'w');
fwrite($fp, $rawdata);
fclose($fp);
}
用法:
<?php $url = "koonk.com/images/logo.png"; $rename = "koonk.png"; imagefromURL($url,$rename); ?>
本文共计86个文字,预计阅读时间需要1分钟。
phpfunction imagefromURL($image, $rename) { $ch=curl_init($image); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $rawdata=curl_exec($ch); curl_close($ch); $fp=fopen($rename, wb);}
function imagefromURL($image,$rename)
{
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("$rename",'w');
fwrite($fp, $rawdata);
fclose($fp);
}
用法:
<?php $url = "koonk.com/images/logo.png"; $rename = "koonk.png"; imagefromURL($url,$rename); ?>

