Use php to share the code of Baidu online drive images. The first code: the regular expression is used to obtain the real address of the files on the Baidu network disk, so as to achieve a straight line effect. Save the following code as downbd. php and copy the code as shown in figure
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. php
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? 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.
The code is as follows:
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.
Direct use on web pages
Baidu uses regular expressions to obtain the real address of the Baidu online storage file, so that the following code can be saved as downbd. php code such...