想用一个网站的图片,但是他做了Referer防盗链
我使用file_get_contents 获取了图片的内容代码
但是直接使用echo输出 显示的乱码
加上了header("content-type:image/gif");
显示一个X
把内容输出到一个图片中然后再打开就又可以访问代码如下,请问如何解决这个问题<?
function referfile($url,$refer='') {
$opt=array('http'=>array('header'=>"Referer:$refer"));
$context=stream_context_create($opt);
$fileco=file_get_contents($url,false,$context);
return $fileco;
}$filecon= referfile('http://www.paoshu8.com/DownFiles/Book/BookCover/20100520121034_8675.gif','http://www.paoshu8.com');
echo $filecon;
?>
我使用file_get_contents 获取了图片的内容代码
但是直接使用echo输出 显示的乱码
加上了header("content-type:image/gif");
显示一个X
把内容输出到一个图片中然后再打开就又可以访问代码如下,请问如何解决这个问题<?
function referfile($url,$refer='') {
$opt=array('http'=>array('header'=>"Referer:$refer"));
$context=stream_context_create($opt);
$fileco=file_get_contents($url,false,$context);
return $fileco;
}$filecon= referfile('http://www.paoshu8.com/DownFiles/Book/BookCover/20100520121034_8675.gif','http://www.paoshu8.com');
echo $filecon;
?>
$opt=array('http'=>array('header'=>"Referer:$refer"));
$context=stream_context_create($opt);
$fileco=file_get_contents($url,false,$context);$filename = basename($url);file_put_contents($filename,$fileco);
}
header('Content-Type: application/octet-stream');
$filesize = filesize('s.png'); //获得文件大小
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: application/force-download');
header('Content-length: '.$filesize);
header('Content-Disposition: attachment; filename="s.png"');
readfile('s.png');
?>
PHP中利用file_get_contents()函数输出图片PHP中输出图片的方式有多种,下面是PHP中利用file_get_contents()函数输出图片的方法,很简单,也比其它方法性能要好一些。
至于为什么用PHP 输出图片,例如防盗链什么的……
$url=’http://www.chhua.com/test/chhua.jpg’;
$content=file_get_contents($url);
echo $content;
PHP file_get_contents() 函数说明
定义和用法
file_get_contents() 函数把整个文件读入一个字符串中。
和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串。
file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。
语法
file_get_contents(path,include_path,context,start,max_length)参数描述
path必需。规定要读取的文件。
include_path可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 “1″。
context可选。规定文件句柄的环境。context 是一套可以修改流的行为的选项。若使用 null,则忽略。
start可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。
max_length可选。规定读取的字节数。该参数是 PHP 5.1 新加的。说明
对 context 参数的支持是 PHP 5.0.0 添加的。
提示和注释
注释:本函数可安全用于二进制对象。
$str=file_get_contents("./RBAC.GIF");
echo $str;
PHP code
header("content
PHP code
header("content-type:image/gif");
$str=file_get_contents("./RBAC.GIF");
echo $str;