华为网盘有个直链功能,不过需要钱买。我有百度网盘,不过百度的网盘外链不能在网页里直接使用图片 华为的直链功能可以做到。百度哪天也能有这功能就好了。 做了一个小功能,准备放在博客里分享图片。 看代码吧!代码存为bdp.php [php]代码02 | require_once ( 'snoopy.class.php' ); |
05 | $snoopy = new Snoopy(); |
06 | $snoopy -> read_timeout = 0; |
07 | $snoopy -> fetch( $url ); |
08 | $n = $snoopy -> results; |
09 | $regex = '/(_.src=")(.+)(";)/' ; |
11 | preg_match( $regex , $n , $match ); |
13 | if (preg_match( '/.gif/' , $match [2])){ |
14 | header( "Content-type: image/gif" ); |
15 | imagegif(imagecreatefromgif( $match [2])); |
16 | } elseif (preg_match( '/.jpg/' , $match [2])){ |
17 | header( "Content-type: image/jpeg" ); |
18 | imagejpeg(imagecreatefromjpeg( $match [2])); |
19 | } elseif (preg_match( '/.png/' , $match [2])){ |
20 | header( "Content-type: image/png" ); |
21 | imagepng(imagecreatefrompng( $match [2])); |
22 | } elseif (preg_match( '/.wbmp/' , $match [2])){ |
23 | header( "Content-type: image/vnd.wap.wbmp" ); |
24 | imagewbmp(imagecreatefromwbmp( $match [2])); |
snoopy.class.php是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。这个文件可以百度一下。以上文件需要一个支持PHP的空间。百度网盘上传图片并发布分享,取得分享地址后的 shareid=29160&uk=2855065916 参数。 使用 http://你的域名/bdp.php?shareid=29160&uk=2855065916 得到图片,这个地址可以放在CKEditor图像地址中使用。其它编辑器应该也可以。 网页中直接 <img src='http://你的域名/bdp.php?shareid=29160&uk=2855065916' /> 使用
|