rockfileChajian.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * 文件上传管理中心相关接口
  4. */
  5. class rockfileChajian extends Chajian{
  6. protected function initChajian()
  7. {
  8. $url = getconfig('rockfile_url');
  9. $urlb = getconfig('rockfile_localurl');
  10. if($urlb)$url = $urlb;
  11. $this->agentkey = getconfig('rockfile_key');
  12. if(substr($url,-1)!='/')$url.='/';
  13. $this->updatekel = $url;
  14. $this->updatekey = $url.'api.php';
  15. }
  16. public function geturlstr($mod, $act, $can=array())
  17. {
  18. $url = $this->updatekey;
  19. $url.= '?m='.$mod.'&a='.$act.'';
  20. $url.= '&agentkey='.$this->agentkey.'';
  21. $url.= '&websign='.md5($this->rock->HTTPweb).'';
  22. foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
  23. return $url;
  24. }
  25. /**
  26. * get获取数据
  27. */
  28. public function getdata($mod, $act, $can=array())
  29. {
  30. $url = $this->geturlstr($mod, $act, $can);
  31. $cont = c('curl')->getcurl($url);
  32. if(!isempt($cont) && contain($cont, 'success')){
  33. $data = json_decode($cont, true);
  34. }else{
  35. $data = returnerror('无法访问,'.$cont.'');
  36. }
  37. return $data;
  38. }
  39. /**
  40. * post发送数据
  41. */
  42. public function postdata($mod, $act, $can=array(), $cans=array())
  43. {
  44. $url = $this->geturlstr($mod, $act, $cans);
  45. $cont = c('curl')->postcurl($url, $can);
  46. if(!isempt($cont) && contain($cont, 'success')){
  47. $data = json_decode($cont, true);
  48. }else{
  49. $data = returnerror('无法访问,'.$cont.'');
  50. }
  51. return $data;
  52. }
  53. /**
  54. * 同步保存到自己的库
  55. */
  56. public function getsave($fnum)
  57. {
  58. if(!$fnum)return $fnum;
  59. $nums = '';
  60. $fanu = explode(',', $fnum);
  61. $ids = '';
  62. foreach($fanu as $st1){
  63. if(is_numeric($st1)){
  64. $ids.=','.$st1.'';
  65. }else{
  66. $nums.=','.$st1.'';
  67. }
  68. }
  69. if($nums){
  70. $nums = substr($nums, 1);
  71. $barr = $this->getdata('upload','filesaveinfo',array('nums'=>$nums));
  72. return $barr;
  73. }else{
  74. return returnerror('error');
  75. }
  76. }
  77. /**
  78. * 删除文件
  79. */
  80. public function filedel($nums)
  81. {
  82. $barr = $this->getdata('upload','filedel',array('nums'=>$nums));
  83. return $barr;
  84. }
  85. /**
  86. * 上传
  87. */
  88. public function uploadfile($fileid)
  89. {
  90. $fobj = m('file');
  91. $frs = $fobj->getone($fileid);
  92. if(!$frs)return returnerror('1');
  93. $path = ROOT_PATH.'/'.$frs['filepath'];
  94. if(!file_exists($path))return returnerror('404');
  95. $url = $this->geturlstr('upload','upfile', array(
  96. 'optid' => $frs['optid'],
  97. 'optname' => $this->rock->jm->base64encode($frs['optname'])
  98. ));
  99. $result = c('curl')->postcurl($url, array('file' => new CURLFile($path, '', $frs['filename'])), 1);
  100. if(!$result)return returnerror('errors');
  101. if(substr($result,0,1)!='{')return returnerror($result);
  102. $data = json_decode($result, true);
  103. $filenum = arrvalue($data, 'filenum');
  104. $thumbpath = arrvalue($data, 'thumbpath');
  105. if($filenum){
  106. $guar['filenum'] = $filenum;
  107. if($fobj->isimg($frs['fileext']))$guar['thumbplat'] = $thumbpath;
  108. $fobj->update($guar,$fileid);
  109. unlink($path);
  110. $path = ROOT_PATH.'/'.$frs['thumbpath'];
  111. if($path && file_exists($path))unlink($path);
  112. }
  113. return returnsuccess();
  114. }
  115. }
粤ICP备19079148号