Home  >  Article  >  Backend Development  >  Use PHP to realize code sharing of Baidu network disk picture direct link_PHP tutorial

Use PHP to realize code sharing of Baidu network disk picture direct link_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:051280browse

The first code: less code
Get the real address of the file on Baidu Netdisk through regular expressions to achieve the direct link effect

Save the following code as downbd .php

Copy code The code is as follows:

$canshu=$_SERVER["QUERY_STRING" ];
if($canshu=="")
{
die("File does not exist");
}
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 ");
}
?>

Call method:

http://***/downbd.php?shareid =00000&uk=00000
Mainly in the format of ?shareid=00000&uk=00000

Second type:

I made a small function and prepared to put it on the blog

Look at the code! Save the code as bdp.php

Copy the code The code is as follows:

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{}
?>

snoopy.class.php is a php class used to imitate The function of a web browser, it can complete the tasks of obtaining web page content and sending forms. You can search this document on Baidu. The above files require a space that supports PHP. Baidu Netdisk uploads pictures and publishes them for sharing, and obtains the shareid=29160&uk=2855065916 parameter after obtaining the sharing address.
Use http://your domain name/bdp.php?shareid=29160&uk=2855065916 to get the image. This address can be used in the CKEditor image address. Other editors should work as well.
Directly use in the web page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326163.htmlTechArticleThe first code: less code, use regular expressions to obtain the real address of the file on Baidu Netdisk, to achieve For direct link effect, save the following code as downbd.php. Copy the code, such as...