Uomg.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\extend\upload;
  3. class Uomg
  4. {
  5. public $name = '优启梦云存储';
  6. public $ver = '1.0';
  7. private $config = [];
  8. public function __construct($config = []) {
  9. $this->config = $config;
  10. }
  11. public function submit($file_path)
  12. {
  13. $type = $GLOBALS['config']['upload']['api']['uomg']['type'];
  14. $openid = $GLOBALS['config']['upload']['api']['uomg']['openid'];
  15. $key = $GLOBALS['config']['upload']['api']['uomg']['key'];
  16. if(empty($type)){
  17. $type = 'ali';
  18. }
  19. $filePath = ROOT_PATH . $file_path;
  20. $url = 'https://api.uomg.com/api/image.'.$type;
  21. $data = [];
  22. //$data['imgurl'] = 'http://imgsrc.baidu.com/forum/pic/item/09f790529822720edafc8a9d76cb0a46f21faba3.jpg';
  23. $data['file'] = 'multipart';
  24. if (class_exists('CURLFile')) {
  25. $data['Filedata'] = new \CURLFile(realpath($file_path));
  26. } else {
  27. $data['Filedata'] = '@'.realpath($file_path);
  28. }
  29. $html = mac_curl_post($url,$data);
  30. $json = @json_decode($html,true);
  31. if($json['code']=='1'){
  32. $file_path = $json['imgurl'];
  33. empty($this->config['keep_local']) && @unlink($filePath);
  34. }
  35. return $file_path;
  36. }
  37. }