PHP如何通过URL实现图片下载操作?

更新于
2026-09-26 05:32:12
2阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计86个文字,预计阅读时间需要1分钟。

PHP如何通过URL实现图片下载操作?

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); ?>

PHP如何通过URL实现图片下载操作?

本文共计86个文字,预计阅读时间需要1分钟。

PHP如何通过URL实现图片下载操作?

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); ?>

PHP如何通过URL实现图片下载操作?