Home > php教程 > PHP源码 > upyun图片fetch的简单封装

upyun图片fetch的简单封装

PHP中文网
Release: 2016-05-25 16:59:37
Original
1115 people have browsed it

php代码:

<?php
header("Content-type: text/html; charset=utf-8");
require_once(&#39;./upyun.class.php&#39;);
$upyun = new UpYun(&#39;空间&#39;, &#39;账户&#39;, &#39;密码&#39;);
$root = &#39;根目录&#39;;

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

	    $rsp = $upyun->writeFile($imgPath, $fh, True);   // 上传图片,自动创建目录
		return $imgPath;
	    //fclose($fh);
	    
	}
	catch(Exception $e) {
	    echo $e->getCode();
	    echo $e->getMessage();
	}
	
}
fetch(&#39;http://res.fuliqu.com/bbs/upload/forum/cj/2014/03/14/13947880739402.png&#39;);
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template