CDN.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * CDN云端接口
  4. *
  5. * @author: dogstar 2015-03-17
  6. */
  7. class Api_CDN extends PhalApi_Api
  8. {
  9. const CODE_MISS_UPLOAD_FILE = 1;
  10. const CODE_FAIL_TO_UPLOAD_FILE = 2;
  11. const CODE_FAIL_TO_UPDATE = 3;
  12. public function uploadFile()
  13. {
  14. $rs = array('code' => self::CODE_FAIL_TO_UPLOAD_FILE, 'url' => '', 'msg' => T('fail to upload file'));
  15. if (!isset($_FILES['file'])) {
  16. $rs['code'] = self::CODE_MISS_UPLOAD_FILE;
  17. $rs['msg'] = T('miss upload file');
  18. return $rs;
  19. }
  20. if ($_FILES["file"]["error"] > 0) {
  21. $rs['code'] = self::CODE_FAIL_TO_UPLOAD_FILE;
  22. $rs['msg'] = T('failed to upload file with error: {error}', array('error' => $_FILES['file']['error']));
  23. DI()->logger->debug('failed to upload file with error: ' . $_FILES['file']['error']);
  24. return $rs;
  25. }
  26. $url = DI()->qiniu->uploadFile($_FILES['file']['tmp_name']);
  27. if (!empty($url)) {
  28. $rs['code'] = 0;
  29. $rs['url'] = $url;
  30. $rs['msg'] = '';
  31. }
  32. @unlink($_FILES['file']['tmp_name']);
  33. return $rs;
  34. }
  35. }