upyun图片fetch的简单封装
程序员文章站
2022-04-11 12:48:36
...
php代码:
<?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');
上一篇: mysql_num_rows VS COUNT 效率问题分析_PHP
下一篇: PHP之数组遍历