<?php
$values="http://wiki.mbalib.com/w/images/3/35/%E7%BB%93%E6%9E%84%E6%80%A7%E5%8D%B1%E6%9C%BA%E7%9A%84%E8%A6%81%E7%B4%A0.jpg";
function getimg($url, $filepath) {
if ($url == '') {
return false;
}
$ext = strrchr($url, '.');
// if ($ext != '.gif' && $ext != '.jpg') {
// return false;
//}
//判断路经是否存在
!is_dir($filepath)?mkdir($filepath):null;
//获得随机的图片名,并加上后辍名
$filename=uniqid().".jpg";
//读取图片
$img = fetch_urlpage_contents($url);
//指定打开的文件
//$fp = @ fopen($filepath.'/'.$filename, 'a');
$fp = @ fopen($filename, 'a');
//写入图片到指定的文本
fwrite($fp, $img);
fclose($fp);
return $filename;
}
function fetch_urlpage_contents($url){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:110.80.7.42', 'CLIENT-IP:110.80.7.42')); //构造IP
curl_setopt($ch, CURLOPT_REFERER, "http://wiki.mbalib.com/ "); //构造来路
//curl_setopt($ch, CURLOPT_HEADER, 1);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
echo getimg($values,"aaa") //图片地址 //保存路径 //返回保存后路径
: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in
评论 (0)