Sina.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Upload\Lib\Store;
  3. use Dever;
  4. class Sina extends Core implements Config
  5. {
  6. public $yun = true;
  7. /**
  8. * 上传文件
  9. *
  10. * @return mixed
  11. */
  12. public function save()
  13. {
  14. list($yun, $file) = $this->yun();
  15. $options = array();
  16. $method = Dever::load('upload/lib/view/sina')->connect($yun, $this->config, $file);
  17. $ret = $method->upload($file, $this->data['file']['tmp_name'], $options, $this->base64);
  18. if ($ret) {
  19. $this->output['url'] = $ret;
  20. $this->file = $this->output['url'];
  21. $file = Dever::load('upload/file-name', array('where_name' => $this->name, 'where_upload' => $this->data['key'], 'rand' => time()));
  22. if (isset($file) && $file) {
  23. $this->update($file['id']);
  24. } else {
  25. $this->insert();
  26. }
  27. return $this->output['url'];
  28. }
  29. }
  30. public function file()
  31. {
  32. if ($this->base64 && isset($this->data['local'])) {
  33. $data = parse_url($this->data['local']);
  34. $data['path'] = str_replace(Dever::data() . 'upload/', '', $data['path']);
  35. $this->path = ltrim($data['path'], '/');
  36. }
  37. $this->file = $this->path . $this->name . $this->ext;
  38. $this->output['file'] = $this->file;
  39. $this->output['url'] = $this->host . $this->file;
  40. //$this->output['url'] = '{uploadYun}' . $this->file;
  41. return $this->output['file'];
  42. }
  43. public function handle_w($water)
  44. {}
  45. public function handle_t($id)
  46. {}
  47. public function handle_c($id)
  48. {}
  49. }