清理防盗链图片的方法
<?php
$url = $_GET["url"];
//$url = str_replace("http:/","http://",$url);
$dir = pathinfo($url);
$host = $dir['dirname'];
$refer = $host.'/';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//Activation can modify the page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
header("Content-type: image/jpeg");//Code to support jpeg, need to modify to support other image formats
print( $data );
?>
调用方式:i.php?url=图片地址
例如:
http://www.1031a.com/i.php?url=http://www.chinabank100.com/templets/images/top-logo.gif
文章由读书网http://www.badcatxt.com编辑整理