用php实现百度网盘图片直链的代码分享
第一种代码:代码量较少
通过正则表达式获取百度网盘的文件真实地址,来实现直链的效果
将下面的代码保存为downbd.php
复制代码 代码如下:
$canshu=$_SERVER["QUERY_STRING"];
if($canshu=="")
{
die("文件不存在");
}
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");
}
?>
调用方法:
http://***/downbd.php?shareid=00000&uk=00000
主要是?shareid=00000&uk=00000这样的格式
第二种:
做了一个小功能,准备放在博客里分享图片。
看代码吧!代码存为bdp.php
复制代码 代码如下:
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是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。这个文件可以百度一下。以上文件需要一个支持PHP的空间。百度网盘上传图片并发布分享,取得分享地址后的 shareid=29160&uk=2855065916 参数。
使用 http://你的域名/bdp.php?shareid=29160&uk=2855065916 得到图片,这个地址可以放在CKEditor图像地址中使用。其它编辑器应该也可以。
网页中直接

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.