Oss.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. if ( ! defined('BASE_PATH')) exit('No direct script access allowed');
  3. class StorageHandle{
  4. public $instance;
  5. public $headurl;
  6. public $domain;
  7. public function __construct(){
  8. $this->domain = DOMAIN;
  9. require dirname(__FILE__).'/oss/sdk.class.php';
  10. $this->instance = new ALIOSS();
  11. $this->headurl = 'http://oss.aliyuncs.com/'.DOMAIN.'/';
  12. }
  13. public function exists($filename){
  14. $res=$this->instance->is_object_exist($this->domain,$this->get_file($filename));
  15. if($res->status==404){
  16. return false;
  17. }
  18. return true;
  19. }
  20. public function read($filename){
  21. $bucket = $this->domain;
  22. $object = $this->get_file($filename);
  23. $options = array(
  24. //ALIOSS::OSS_FILE_DOWNLOAD => "d:\\cccccccccc.sh",
  25. //ALIOSS::OSS_CONTENT_TYPE => 'txt/html',
  26. );
  27. $response = $this->instance->get_object($bucket,$object,$options);
  28. return $contents;
  29. }
  30. public function write($name,$content){
  31. $object = $this->get_file($name);
  32. $upload_file_options = array(
  33. 'content' => $content,
  34. 'length' => strlen($content),
  35. ALIOSS::OSS_HEADERS => array(
  36. //'Expires' => '2012-10-01 08:00:00',
  37. ),
  38. );
  39. $response = $this->instance->upload_file_by_content($this->domain,$object,$upload_file_options);
  40. }
  41. public function url($name){
  42. return $this->headurl.$this->get_file($name);
  43. }
  44. public function error(){
  45. return false;
  46. }
  47. public function delete($name){
  48. return $this->instance->delete_object($this->domain,$this->get_file($name));
  49. }
  50. private function get_file($name){
  51. return ltrim($name,'/');
  52. }
  53. }