Upyun.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\extend\upload;
  3. use Upyun\Upyun as upOper;
  4. use Upyun\Config;
  5. class Upyun
  6. {
  7. public $name = '又拍云存储';
  8. public $ver = '1.0';
  9. private $config = [];
  10. public function __construct($config = []) {
  11. $this->config = $config;
  12. }
  13. public function submit($file_path)
  14. {
  15. $bucket = $GLOBALS['config']['upload']['api']['upyun']['bucket'];
  16. $username = $GLOBALS['config']['upload']['api']['upyun']['username'];
  17. $pwd = $GLOBALS['config']['upload']['api']['upyun']['pwd'];
  18. require_once ROOT_PATH . 'extend/upyun/vendor/autoload.php';
  19. $bucketConfig = new Config($bucket, $username, $pwd);
  20. $client = new upOper($bucketConfig);
  21. $_file = fopen($file_path, 'r');
  22. $a = $client->write($file_path, $_file);
  23. $filePath = ROOT_PATH . $file_path;
  24. unset($_file);
  25. empty($this->config['keep_local']) && @unlink($filePath);
  26. return $GLOBALS['config']['upload']['api']['upyun']['url'] . '/' . $file_path;
  27. }
  28. }