第一种代码:代码量较少
通过正则表达式获取百度网盘的文件真实地址,来实现直链的效果
将下面的代码保存为downbd.php
复制代码 代码如下:
$canshu=$_SERVER["QUERY_STRING"];
if($canshu=="")
{
die("文件不存在");
}
else
{
$wangzhi="http://pan.baidu.com/share/link?".$canshu;
$file=file_get_contents($wangzhi);
$pattern='/a>/i';
preg_match_all($pattern,$file,$result);
$tempurl=implode("",$result[1]);
$fileurlt=str_replace("\"","",$tempurl);
$fileurl=str_replace("&","&",$fileurlt);
header("location:$fileurl");
}
?>
复制代码 代码如下:
require_once('snoopy.class.php');
//http://www.abc.com/bdp.php?shareid=29160&uk=2855065916
$url = 'http://pan.baidu.com/share/link?shareid=' . $_GET['shareid'] . '&uk=' . $_GET['uk'];
$snoopy = new Snoopy();
$snoopy -> read_timeout = 0;
$snoopy -> fetch($url);
$n = $snoopy -> results;
$regex = '/(_.src=")(.+)(";)/';
$match = '';
preg_match($regex, $n, $match);
if(preg_match('/.gif/', $match[2])){
header("Content-type: image/gif");
imagegif(imagecreatefromgif($match[2]));
}elseif(preg_match('/.jpg/', $match[2])){
header("Content-type: image/jpeg");
imagejpeg(imagecreatefromjpeg($match[2]));
}elseif(preg_match('/.png/', $match[2])){
header("Content-type: image/png");
imagepng(imagecreatefrompng($match[2]));
}elseif(preg_match('/.wbmp/', $match[2])){
header("Content-type: image/vnd.wap.wbmp");
imagewbmp(imagecreatefromwbmp($match[2]));
}else{}
?>