龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

upyun图片fetch的简单封装

时间:2014-07-22 14:48来源: 作者: 点击:
分享到:
最近做了一个论坛http://bbs.fuliqu.com/然后打算写个采集器,但是采集到的内容的图片都是防盗链的,我得防盗我的upyun的云存储里。下面代码仅供各位参考,写的不好,大神不要喷
最近做了一个论坛
http://bbs.fuliqu.com/
然后打算写个采集器,但是采集到的内容的图片都是防盗链的,我得防盗我的upyun的云存储里。

下面代码仅供各位参考,写的不好,大神不要喷
<?php
header("Content-type: text/html; charset=utf-8");
require_once('./upyun.class.php');
$upyun = new UpYun('空间', '账户', '密码');
$root = '根目录';

function microtime_float()
{
   list($usec, $sec) = explode(" ", microtime());
   $s =  ((float)$usec + (float)$sec);
   return  str_replace('.','',$s);
}
function fetch($u){
	try {
	    global $upyun,$root;
	    $fh = file_get_contents($u);
		//$fh = 'var newsClose = '.$fh;
		$imgPath = $root.'/'.date('Y').'/'.date('m').'/'.date('d').'/'.microtime_float().'.png';
		
		//die();

	    $rsp = $upyun->writeFile($imgPath, $fh, True);   // 上传图片,自动创建目录
		return $imgPath;
	    //fclose($fh);
	    
	}
	catch(Exception $e) {
	    echo $e->getCode();
	    echo $e->getMessage();
	}
	
}
fetch('http://res.fuliqu.com/bbs/upload/forum/cj/2014/03/14/13947880739402.png');
精彩图集

赞助商链接