First code: less code
Use regular expressions to obtain the real address of Baidu online storage files to Achieve straight-chain effect.
Save the following code as downbd. phpCopy codeThe Code is as follows: <? Php
$ 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> <a class = "dbtn cancel singledbtn" href = (.*?) Id = "downFileButtom">/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? Consumer id = 00000 & uk = 00000
Mainly? Consumer id = 00000 & uk = 00000 format
Second:
A small function is provided to share images in a blog.
Check the code! The code is saved as bdp. php.
Copy codeThe Code is as follows: <? Php
Require_once ('snoopy. class. php ');
// Http://www.abc.com/bdp.php? Consumer id = 29160 & uk = 2855065916
$ Url = 'HTTP: // pan.baidu.com/#/link? Upload id = '. $ _ GET ['upload id'].' & 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 functions of a web browser. It can complete the tasks of obtaining webpage content and sending forms. This file can be Baidu. The above file requires a space that supports PHP. Baidu online storage uploads images and publishes shares. After obtaining the share address, the consumer id = 29160 & uk = 2855065916 parameter.
Use http: // your domain name/bdp. php? Upload id = 29160 & uk = 2855065916 to get the image. This address can be used in the CKEditor image address. Other Editors should also be supported.
Use