Use php to implement code sharing of Baidu online drive Images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.