您可以发布博客文章。
2012-09-28 14:52
183 查看
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * Description of CUrl * * @author Administrator */ class CUrl { private static $curl = null; private static $mcurl = null; public static function start() { self::$curl = curl_init(); curl_setopt(self::$curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt(self::$curl, CURLOPT_HEADER, 0); } /** * 取得页面信息 * @param type $url * @return type */ public static function Info($url){ self::start(); curl_setopt(self::$curl, CURLOPT_URL, $url); $info = curl_getinfo(self::$curl); self::close(); return $info; } /** * 下载图片 * @param string $url * @param string $savepath */ public static function Download($url,$savepath){ $content = CUrl::Http($url); preg_match_all('/http:\/\/[^\?^\,]*?jpg/i', $content, $matches); list($jpgs) = $matches; $index = @$_GET['index'] ? @$_GET['index'] : 0; $count = count($jpgs); /*echo "<pre>"; print_r($jpgs); echo "</pre>"; die;*/ $pic = CUrl::Http($jpgs[$index], null, $info); if(!in_array($info['http_code'],array('404','302')) && $pic) file_put_contents("{$savepath}/{$index}.jpg", $pic); $index++; if($index==($count-1)) exit('<br/>the End'); exit('<meta http-equiv="refresh" content="0; url=' . urldecode("http://www.qweibo.com/test.php?index={$index}") . '"/>'); } /** * 请求一个地址 * @param string $url * @param array $post array("content" => "我是post值","upload" => "@F:/image/dsfdsf.rar"//要上传的本地文件地址) * @return 返回请求地址的页面内容 */ public static function Http($url, $post=null, &$info=array() , $timeout = null){ self::start(); curl_setopt(self::$curl, CURLOPT_URL, $url); if(!emptyempty($post)){//POST($_POST)和上传文件($_FILES)都可 $options = array( CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $post, ); curl_setopt_array(self::$curl, $options); } if(!is_array($info)) { @$info = curl_getinfo(self::$curl);//取得请求信息 如果传了引用的话就不再是默认值array(),引用的值是为空的 } if($timeout){ //设置超时时间 curl_setopt ( self::$curl, CURLOPT_TIMEOUT, $timeout ); } $output = curl_exec(self::$curl); if($output === false) { return 'Curl error: ' . curl_error(self::$curl);//返回一个保护当前会话最近一次错误的字符串 } self::close(); return $output; } /** * 一次请求多个地址 * @param array $urls 多个地址 * @param array $posts 每个地址对应的POST数据 二维数组 * @return 返回所有地址的内容 */ public static function MultiHttp($urls, $posts=null){ self::$mcurl = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); if(!emptyempty($posts[$i])){//POST($_POST)和上传文件($_FILES)都可 $options = array( CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $posts[$i], ); curl_setopt_array($conn[$i], $options); } curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1); curl_multi_add_handle (self::$mcurl,$conn[$i]); } do { $n=curl_multi_exec(self::$mcurl,$active); } while ($active); foreach ($urls as $i => $url) { $outputs[$i]=curl_multi_getcontent($conn[$i]); curl_close($conn[$i]); } return $outputs; } public function close(){ curl_close(self::$curl); } } ?>
相关文章推荐
- m2014-software->Word2010发布博客文章至Cnblogs
- 据说 wiz 2.0 版有了可以发布到博客的功能
- 整理发布本人所有博客文章中涉及的代码与工具(大部分是C++和Java)
- 在云服务器搭建WordPress博客(六)发布和管理文章
- 使用Word2007发布博客文章的方法汇总(转)
- 在Word2007中发布CSDN博客文章
- Word2010发布博客文章至Cnblogs
- 使用小书匠编辑器将文章快速发布到各大主要博客平台
- [置顶] 很荣幸被选为2013年度 CSDN博客之星评选,如果觉得我的文章可以,请投我一票!
- 如何使用live writer客户端来发布CSDN的博客文章?
- Spring boot 搭建个人博客系统(四)——文章的发布和分页显示
- 使用Windows live writer客户端来发布CSDN的博客文章
- HEXO搭建个人博客(一):发布第一篇文章
- 如何使用Windows Live Writer在博客园发布文章【博客园新手可以看看哦】
- 使用github+sublime+markdwon 写文章,写博客并发布到博客园
- 使用Windows Live Writer 2011发布文章到51cto博客
- 重新发布本人所有博客文章中涉及的代码与工具(大部分是C++和Java)
- 可以通过 windows live writer 发布我的博客了
- 在CSDN开通博客专栏后如何发布文章(图文)
- 使用word 2010 发布博客文章的方法