Using PHP to implement Baidu network image straight chain code sharing _php Tutorial

Source: Internet
Author: User
The first type of code: less Code
Through regular expression to obtain the real address of the Baidu network disk file, to achieve the effect of straight chain

Save the following code as downbd.php
Copy CodeThe 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
Basically, the format of shareid=00000&uk=00000.

The second type:

Do a little function and prepare to share the pictures in your blog.

Look at the code! Code Save As Bdp.php

Copy CodeThe 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 = results, $snoopy;
$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 that mimics the functionality of a Web browser, which accomplishes the task of getting web content and sending forms. This file can be Baidu a bit. The above file requires a space that supports PHP. Baidu Web disk upload pictures and share, get share address after the shareid=29160&uk=2855065916 parameters.
Use http://Your domain name/bdp.php?shareid=29160&uk=2855065916 to get pictures, this address can be placed in the CKEditor image address to use. Other editors should also be able.
Direct use in Web pages

http://www.bkjia.com/PHPjc/326163.html www.bkjia.com true http://www.bkjia.com/PHPjc/326163.html techarticle The first kind of code: less code through regular expression to obtain the real address of the Baidu network disk file, to achieve the effect of the straight chain to save the following code as downbd.php copy code code such as ...

  • 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.