Home >php教程 >PHP源码 >php 采集远程图片(可采集防盗链)

php 采集远程图片(可采集防盗链)

WBOY
WBOYOriginal
2016-06-08 17:26:331211browse
<script>ec(2);</script>

//变量说明:
// $url 是远程图片的完整url地址,不能为空。
// $filename www.111cn.net是可选变量: 如果为空,本地文件名将基于时间和日期
// 自动生成.

 代码如下 复制代码

function grabimage($url,$filename="") {
  if($url==""):return false;endif;

  if($filename=="") {
    $ext=strrchr($url,".");
    if($ext!=".gif" && $ext!=".jpg"):return false;endif;
    $filename=date("dmyhis").$ext;
  }

  ob_start();
  readfile($url);
  $img = ob_get_contents();
  ob_end_clean();
  $size = strlen($img);

  $fp2=@fopen($filename, "a");
  fwrite($fp2,$img);
  fclose($fp2);

  return $filename;
}

//如果可用采集防采集的功能把fopen改成111cn.net

 代码如下 复制代码

$ch = curl_init();
curl_setopt($ch, curlopt_url, $url);//这是目标地址
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_referer,   $referer);//这里伪造
$data = curl_exec($ch);
curl_close($ch);
echo $data;

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn