2、curl的方法
用法:
-
- http://your-domain-name/showpic.php?url=image_url
复制代码
3、PHP header发送各种类型文件下载
文件名:showpic.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);
-
- $ext = strtolower(substr(strrchr($img,'.'),1,10));
- $types = array(
- 'gif'=>'image/gif',
- 'jpeg'=>'image/jpeg',
- 'jpg'=>'image/jpeg',
- 'jpe'=>'image/jpeg',
- 'png'=>'image/png',
- );
- $type = $types[$ext] ? $types[$ext] : 'image/jpeg';
- header("Content-type: ".$type);
- echo $data;
- ?>
-
复制代码
遇到PHP 提示错误Cannot modify header information headers already sent ,原因在于:这些代码之前不要有任何内容输出的,包括空白,切记!
有了以上的代码,就可以这样显示图片了:
真是道高一尺,魔高一丈啊,php图片防盗链就这样没有守住防线,哈哈。
|