uploadAction.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <?php
  2. class uploadClassAction extends apiAction
  3. {
  4. /**
  5. * 上传文件
  6. */
  7. public function upfileAction()
  8. {
  9. if(!$_FILES)exit('sorry!');
  10. $upimg = c('upfile');
  11. $maxsize= (int)$this->get('maxsize', $upimg->getmaxzhao());//上传最大M
  12. $uptypes= '*';
  13. $updir = $this->get('updir');
  14. if(isempt($updir)){
  15. $updir=date('Y-m');
  16. }else{
  17. $updir=str_replace(array(' ','.'),'', trim($updir));
  18. $updir=str_replace('{month}',date('Y-m'), $updir);
  19. $updir=str_replace('{Year}',date('Y'), $updir);
  20. $updir=str_replace(array('{','}'),'', $updir);
  21. $updir=str_replace(',','|', $updir);
  22. $bobg = preg_replace("/[a-zA-Z0-9_]/",'', $updir);
  23. $bobg = str_replace(array('-','|'),'', $bobg);
  24. if($bobg)exit('stop:'.$bobg.'');
  25. }
  26. $upimg->initupfile($uptypes, ''.UPDIR.'|'.$updir.'', $maxsize);
  27. $upses = $upimg->up('file');
  28. if(!is_array($upses))exit($upses);
  29. $arr = c('down')->uploadback($upses);
  30. $arr['autoup'] = (getconfig('qcloudCos_autoup') || getconfig('alioss_autoup')) ? 1 : 0; //是否上传其他平台
  31. $this->returnjson($arr);
  32. }
  33. /**
  34. * 从编辑文件中心获取最新编辑的文件20250610
  35. */
  36. public function editfilebAction()
  37. {
  38. //用那个异步去获取(待开发)
  39. $fileid = (int)$this->get('fileid','0');
  40. $frs = m('file')->getone($fileid);
  41. if(!$frs)return 'error';
  42. $editobj= c('rockedit');
  43. $barr = $editobj->getdata('file','history', array(
  44. 'filekey' => getconfig('xinhukey'),
  45. 'filenum' => $frs['onlynum'],
  46. ));
  47. if(!$barr['success'])return $barr['msg'];
  48. $arr = $barr['data'];
  49. $data = file_get_contents($arr['url']);
  50. $result = $this->upfilevb_Query($fileid, $frs['fileext'], $data);
  51. if(substr($result,0,2)=='ok'){
  52. $editobj->getdata('file','upresult', array(
  53. 'isup' => 3,
  54. 'upid' => $arr['upid'],
  55. ));
  56. return '“'.$frs['filename'].'”文件编辑已完成';
  57. }else{
  58. return '编辑失败;';
  59. }
  60. }
  61. //判断是否编辑完成
  62. public function editfilecAction()
  63. {
  64. $fileid = (int)$this->get('fileid','0');
  65. $erand = $this->get('erand');
  66. $frs = m('file')->getone($fileid);
  67. if(!$erand || !$frs)return 'error';
  68. $barr = c('rockedit')->getdata('file','editfilec', array(
  69. 'filekey' => getconfig('xinhukey'),
  70. 'filenum' => $frs['onlynum'],
  71. 'erand' => $erand
  72. ));
  73. if($barr['success'])return $barr['data'];
  74. return 'wait';
  75. }
  76. /**
  77. * 这个是用来在线编辑文档上传的
  78. */
  79. public function upfilevbAction()
  80. {
  81. $fileid = (int)$this->get('fileid','0');
  82. $fileext= $this->get('fileext');
  83. $data = $this->getpostdata();
  84. if(isempt($data))return '没有数据';
  85. return $this->upfilevb_Query($fileid, $fileext, base64_decode($data));
  86. }
  87. public function upfilevb_Query($fileid, $fileext, $data)
  88. {
  89. if($fileid==0)return 'error';
  90. $fileobj = m('file');
  91. $frs = $fileobj->getone($fileid); //记录
  92. if(!$frs) return '文件记录不存在了';
  93. if(!$fileext)$fileext = $frs['fileext'];
  94. $uptype = '|doc|docx|xls|xlsx|ppt|pptx|';
  95. if(!contain($uptype,'|'.$fileext.'|'))$fileext='doc';
  96. $frs['oldfilepath'] = $frs['filepath'];
  97. $filename = $frs['filename'];
  98. if(!contain($filename, '.'.$fileext.'')){
  99. $filename = str_replace(array('.doc','.xls','.ppt'), '.'.$fileext.'', $filename);
  100. }
  101. $filepath = ''.UPDIR.'/'.date('Y-m').'/'.date('d_His').''.rand(10,99).'.'.$fileext.'';
  102. $this->rock->createtxt($filepath, $data);
  103. $filesize = filesize($filepath);
  104. $filesizecn = $this->rock->formatsize($filesize);
  105. //更新文件
  106. $fileobj->update(array(
  107. 'filename' => $filename,
  108. 'filepath' => $filepath,
  109. 'filenum' => '',
  110. 'filesize' => $filesize,
  111. 'filesizecn' => $filesizecn,
  112. 'fileext' => $fileext,
  113. 'filepathout' => '',
  114. 'pdfpath' => '',
  115. ),$fileid);
  116. c('cache')->del('filetopdf'.$fileid.'');
  117. //【弃用】发队列自动上传到信呼文件平台
  118. if(getconfig('autoup_toxinhudoc')){
  119. //c('rockqueue')->sendfile($fileid);
  120. }
  121. //上传到腾讯存储
  122. if(getconfig('qcloudCos_autoup')){
  123. c('rockqueue')->sendfile($fileid);
  124. }
  125. //告诉上传人说编辑了他的附件
  126. $mknums = arrvalue($frs,'mknum');
  127. if(!isempt($mknums) && $frs['mid']>0){
  128. $mid = $frs['mid'];
  129. $mknumsa = explode('|', $mknums);
  130. $modenum = $mknumsa[0];
  131. if(isset($mknumsa[1]))$mid = $mknumsa[1];
  132. $flow = m('flow')->initflow($modenum, $mid, false);
  133. $ssid = $flow->addlog(array(
  134. 'name' => '在线编辑'
  135. ));
  136. $ufrs = $frs;
  137. $ufrs['filepath'] = $frs['oldfilepath'];
  138. unset($ufrs['oldfilepath']);
  139. unset($ufrs['id']);
  140. unset($ufrs['onlynum']);
  141. $ufrs['mtype'] = 'flow_log';
  142. $ufrs['mid'] = $ssid;
  143. $ufrs['mknum'] = ''.$modenum.'|'.$mid.'';
  144. $ufrs['filename'] = str_replace('.'.$ufrs['fileext'].'','(备份).'.$ufrs['fileext'].'', $ufrs['filename']);
  145. $fileobj->insert($ufrs); //记录原来的文件
  146. //不是我创建就告诉创建人
  147. if($this->adminid<>$frs['optid'])
  148. $flow->push($frs['optid'],'', ''.$this->adminname.'在线编辑文件“'.$frs['filename'].'”', '文件在线编辑');
  149. $flow->floweditoffice($frs, $ufrs);
  150. }else if($this->adminid<>$frs['optid']){ //不知道关联哪个模块
  151. $flow = m('flow')->initflow('word');
  152. $flow->push($frs['optid'],'文档', ''.$this->adminname.'在线编辑文件“'.$frs['filename'].'”', '文件在线编辑',0, array(
  153. 'wxurl' => ''
  154. ));
  155. }
  156. $frs['filesize'] = $filesize;
  157. $fkey = $this->createtempurl($frs);
  158. return 'ok,'.$fkey.'';
  159. }
  160. /**
  161. * 上传时初始化看是不是存在文件
  162. */
  163. public function initfileAction()
  164. {
  165. $cobj = c('check');
  166. $filesize = $cobj->onlynumber($this->post('filesize'));
  167. $fileext = $cobj->repotr($this->post('fileext'));
  168. $filename = $cobj->repotr($this->getvals('filename'));
  169. $where = "`fileext`='$fileext' and `filesize`='$filesize'";
  170. if(!isempt($filename))$where.=" and `filename`='$filename'";
  171. $frs = m('file')->getone($where,'*','`id` desc');
  172. $bo = false;
  173. if($frs){
  174. $filepath = $frs['filepath'];
  175. if(!isempt($filepath) && file_exists($filepath))$bo=true;
  176. }
  177. if($bo){
  178. $this->showreturn(json_encode($frs));
  179. }else{
  180. $this->showreturn('','not found', 201);
  181. }
  182. }
  183. public function upfileappAction()
  184. {
  185. if(!$_FILES)$this->showreturn('', '禁止访问', 201);
  186. $upimg = c('upfile');
  187. $maxsize= (int)$this->get('maxsize', $upimg->getmaxzhao());//上传最大M
  188. $uptypes= '*';
  189. $upimg->initupfile($uptypes, ''.UPDIR.'|reimchat|'.date('Y-m').'', $maxsize);
  190. $upses = $upimg->up('file');
  191. if(!is_array($upses))$this->showreturn('', $upses, 202);
  192. $arr = c('down')->uploadback($upses);
  193. $this->showreturn($arr);
  194. }
  195. public function upcontAction()
  196. {
  197. $cont = $this->post('content');
  198. if(isempt($cont))exit('sorry not cont');
  199. $cont = str_replace(' ','', $cont);
  200. $cont = $this->rock->jm->base64decode($cont);
  201. $arr = c('down')->createimage($cont,'png','截图');
  202. $this->returnjson($arr);
  203. }
  204. public function getfileAjax()
  205. {
  206. $cont = '';
  207. $path = ''.UPDIR.'/uptxt'.$this->adminid.'.txt';
  208. if(file_exists($path)){
  209. @$cont = file_get_contents($path);
  210. }
  211. $data = array();
  212. if($cont!=''){
  213. $arr = json_decode($cont, true);
  214. $msg = $arr['msg'];
  215. $data = $arr['data'];
  216. @unlink($path);
  217. }else{
  218. $msg = 'sorry,not infor!';
  219. }
  220. $this->showreturn($data, $msg);
  221. }
  222. public function getfileAction()
  223. {
  224. $fileid = (int)$this->post('fileid',0);
  225. $rs = m('file')->getone($fileid);
  226. $this->showreturn($rs);
  227. }
  228. public function downAction()
  229. {
  230. $id = (int)$this->jm->gettoken('id');
  231. m('file')->show($id);
  232. }
  233. //记录预览记录
  234. public function logsAction()
  235. {
  236. $fileid = (int)$this->post('fileid',0);
  237. $type = (int)$this->post('type',0);
  238. m('file')->addlogs($fileid, $type);
  239. }
  240. /**
  241. * 发送编辑权限
  242. */
  243. public function rockofficeeditAction()
  244. {
  245. $fileid = (int)$this->get('id');
  246. $lx = (int)$this->get('lx');
  247. $frs = m('file')->getone($fileid);
  248. if(!$frs)return returnerror('文件不存在了');
  249. $filepath = $frs['filepath'];
  250. $filepathout = $frs['filepathout'];
  251. if(substr($filepath,0,4)!='http' && !file_exists($filepath)){
  252. if(isempt($filepathout)){
  253. return returnerror('文件不存在了1');
  254. }else{
  255. $filepath = $filepathout;
  256. }
  257. }
  258. $uptype = '|doc|docx|xls|xlsx|ppt|pptx|';
  259. if(!contain($uptype,'|'.$frs['fileext'].'|'))return returnerror('不是文档类型无法在线编辑');
  260. $filename = $frs['filename'];
  261. $utes = 'edit';
  262. if($lx==1){
  263. $filename = '(只读)'.$filename.'';
  264. $utes = 'yulan';
  265. }
  266. $arr = array();
  267. $arr[0] = URL;
  268. $arr[1] = $filename;
  269. $arr[2] = $this->createtempurl($frs);
  270. $arr[3] = $this->rock->gethttppath($filepath); //下载地址
  271. $arr[4] = $fileid;
  272. $arr[5] = $this->adminid;
  273. $arr[6] = $this->token;
  274. $arr[7] = $utes;
  275. $arr[8] = $frs['fileext'];
  276. $str = '';
  277. foreach($arr as $s1)$str.=','.$s1.'';
  278. return returnsuccess(substr($str,1));
  279. }
  280. /**
  281. * 获取预览和下载地址
  282. */
  283. public function fileinfoAction()
  284. {
  285. $fileid = (int)$this->get('id');
  286. $type = (int)$this->get('type'); //0预览,1下载,2编辑
  287. $ismobile = (int)$this->get('ismobile'); //是否手机端
  288. return $this->fileinfoShow($fileid, $type, $ismobile);
  289. }
  290. private $frs,$loadyuan;
  291. public function fileinfoShow($fileid, $type, $ismobile)
  292. {
  293. $fobj = m('file');
  294. $frs = $fobj->getone($fileid);
  295. $this->frs = $frs;
  296. if(!$frs)return returnerror('文件不存在了');
  297. $filenum= $frs['filenum'];
  298. $fileext = $frs['fileext'];
  299. $filename = $frs['filename'];
  300. $filepath = $frs['filepath'];
  301. $filepathout = arrvalue($frs, 'filepathout');
  302. $data = array();
  303. $loadyuan = false;
  304. $data['url'] = '';
  305. $data['fileext']= $fileext;
  306. //预览
  307. if($type==0){
  308. if(!$fobj->isview($fileext))
  309. return returnerror('此'.$fileext.'类型文件不支持在线预览');
  310. }
  311. //从文件上传中心最新
  312. if(!isempt($filenum)){
  313. $dbs = m('admin');
  314. $barr = c('rockfile')->getdata('upload','fileinfo', array(
  315. 'fnum' => $filenum,
  316. 'lx' => $type,
  317. 'sysuid' => $this->adminid,
  318. 'ismobile' => $ismobile,
  319. 'sysname' => $this->rock->jm->base64encode($this->adminname),
  320. 'sysface' => $this->rock->jm->base64encode($dbs->getface($dbs->getmou('face',$this->adminid))),
  321. ));
  322. if(!$barr['success']){
  323. return $barr;
  324. }else{
  325. $loadyuan = true;
  326. $da = $barr['data'];
  327. $data['url'] = $da['url'];
  328. if($da['isimg'] && $type==0)$data['url'] = $da['imgurl'];
  329. }
  330. }
  331. $this->loadyuan = $loadyuan;
  332. //存自己服务器的
  333. if(!$loadyuan){
  334. if(substr($filepath,0,4)!='http' && isempt($filepathout) && !file_exists($filepath))return returnerror('文件不存在了1');
  335. if(c('upfile')->isimg($fileext)){
  336. $data['url'] = m('admin')->getface($filepath);
  337. if(!isempt($filepathout))$data['url'] = $filepathout;
  338. }
  339. //下载
  340. if($type==1){
  341. $url = 'api.php?m=upload&id='.$fileid.'&a=down';
  342. $url.= '&adminid='.$this->adminid.'&token='.$this->admintoken.'';
  343. $url.= '&filename='.$this->jm->base64encode($frs['filename']).'';
  344. $data['url'] = $url;
  345. }
  346. //编辑
  347. if($type==2){
  348. if(getconfig('officebj')=='1'){
  349. $erand = rand(1000000,9999999);
  350. $data['fileext']= 'rockedit';
  351. $data['url'] = 'index.php?m=public&a=fileedit&id='.$fileid.'&erand='.$erand.'';
  352. $data['editwsinfo'] = c('rockedit')->getwsinfo(array(
  353. 'erand' => $erand,
  354. 'fileid'=> $fileid
  355. ));
  356. /*
  357. c('rockqueue')->push('rockoffice,gedit', array(
  358. 'erand' => $erand,
  359. 'cishu' =>1,
  360. 'fileid' =>$fileid,
  361. 'optid' => $this->adminid
  362. ), time() + 10);*/
  363. }else{
  364. if($ismobile==1)return returnerror('移动端不支持在线编辑');
  365. $data['fileext']='rockoffice';
  366. $data['url'] = $this->rock->gethttppath($filepath);
  367. }
  368. }
  369. }
  370. $data['filename'] = $filename;
  371. $url = arrvalue($data, 'url');
  372. if($url==''){
  373. $url = 'index.php?m=public&a=fileviewer&id='.$fileid.'';
  374. }
  375. //用本地插件编辑和预览
  376. if($data['fileext']=='rockoffice'){
  377. $utes = 'edit';
  378. if($type==0){
  379. $filename = '(只读)'.$filename.'';
  380. $utes = 'yulan';
  381. }
  382. $arr = array();
  383. $arr[0] = URL;
  384. $arr[1] = $filename;
  385. $arr[2] = $this->createtempurl($frs);
  386. $arr[3] = $data['url']; //下载地址
  387. $arr[4] = $fileid;
  388. $arr[5] = $this->adminid;
  389. $arr[6] = $this->token;
  390. $arr[7] = $utes;
  391. $arr[8] = $fileext;
  392. $str = '';
  393. foreach($arr as $s1)$str.=','.$s1.'';
  394. $url = substr($str, 1);
  395. }
  396. $data['url'] = $url;
  397. $data['type'] = $type;
  398. $data['id'] = $fileid;
  399. $data['isview'] = $fobj->isview($fileext); //是否可直接预览
  400. return returnsuccess($data);
  401. }
  402. //生成唯一文件名键值
  403. private function createtempurl($frs)
  404. {
  405. $str = ''.md5(URL).'_'.$frs['filesize'].'_'.$frs['id'].'.'.$frs['fileext'].'';
  406. return $str;
  407. }
  408. /**
  409. * app上获取下载地址
  410. */
  411. public function appgetfileAction()
  412. {
  413. $id = (int)$this->post('id',0);
  414. $barr = $this->fileinfoShow($id, 1, 1);
  415. if(!$barr['success'])return $barr;
  416. $frs = $this->frs;
  417. $frs['filetype'] = m('file')->getmime($frs['fileext']);
  418. $frs['downurl'] = $barr['data']['url'].'&cfrom=app';
  419. if(!$this->loadyuan){
  420. $frs['downurl']= '';
  421. if(substr($frs['filepath'],0,4)=='http'){
  422. $frs['downurl'] = $frs['filepath'];
  423. }else{
  424. if(!file_exists($frs['filepath']) && arrvalue($frs,'filepathout'))$frs['downurl'] = $frs['filepathout'];
  425. }
  426. }
  427. return returnsuccess($frs);
  428. }
  429. /**
  430. * 编辑时验证
  431. */
  432. public function sendeditAction()
  433. {
  434. $id = (int)$this->get('id',0);
  435. $otype = (int)$this->get('otype',0);
  436. return c('rockedit')->sendedit($id, $this->admintoken, $otype);
  437. }
  438. /**
  439. * 获取文件信息
  440. */
  441. public function afileinfoAction()
  442. {
  443. $allfid = c('check')->onlynumber($this->get('allfid'));
  444. $filearr= array();
  445. if($allfid){
  446. $fobj = m('file');
  447. $frows = $fobj->getall('`id` in('.$allfid.')','filename,id,filesizecn,fileext,optname,thumbpath,thumbplat');
  448. foreach($frows as $k1=>$rs1){
  449. $rs1['thumbpath'] = $fobj->getthumbpath($rs1);
  450. $filearr['f'.$rs1['id'].''] = $rs1;
  451. }
  452. }
  453. return $filearr;
  454. }
  455. /**
  456. * 获取文件(写入到内容里)
  457. */
  458. public function filedaoAction()
  459. {
  460. $allfid = c('check')->onlynumber($this->get('fileid'));
  461. $filearr= array();
  462. $str = '';
  463. if($allfid){
  464. $fobj = m('file');
  465. $frows = $fobj->getall('`id` in('.$allfid.')');
  466. $urla = getconfig('outurl', URL);
  467. foreach($frows as $k1=>$rs1){
  468. $str.='<br>';
  469. $url = ''.$urla.''.$rs1['filepath'].'';
  470. if($sst = arrvalue($rs1,'filepathout'))$url = $sst;
  471. $flx = $rs1['fileext'];
  472. if(!contain($fobj->fileall,','.$flx.','))$flx='wz';
  473. $str1 = '';
  474. $imurl = ''.URL.'web/images/fileicons/'.$flx.'.gif';
  475. $thumbpath = $fobj->getthumbpath($rs1);
  476. if($fobj->isimg($flx) && !isempt($thumbpath))$imurl = $thumbpath;
  477. $str.='<img src="'.$imurl.'" align="absmiddle" height=20 width=20> <a target="_blank" href="'.$url.'">'.$rs1['filename'].'</a>('.$rs1['filesizecn'].')';
  478. }
  479. }
  480. return $str;
  481. }
  482. /**
  483. * 获取模版文件
  484. */
  485. public function getmfileAction()
  486. {
  487. $data = array();
  488. $fenlei = $this->jm->base64decode($this->get('fenlei'));
  489. $fenlei = $this->rock->xssrepstr($this->rock->iconvsql($fenlei));
  490. $where = m('admin')->getjoinstr('a.`receid`', $this->adminid, 1);
  491. $sql = 'select a.`name`,a.`wtype`,b.`filepath`,b.`id` from `[Q]wordxie` a left join `[Q]file` b on a.`fileid`=b.`id` where a.`fenlei`=\''.$fenlei.'\' and a.`isgk`=1 and ('.$where.')';
  492. $rows = $this->db->getall($sql);
  493. foreach($rows as $k=>$rs){
  494. $data[] = array(
  495. 'value' => $rs['id'],
  496. 'name' => $rs['name'],
  497. 'subname' => $rs['wtype'],
  498. );
  499. }
  500. return $data;
  501. }
  502. public function getmfilvAction()
  503. {
  504. $fileid = (int)$this->get('fileid','0');
  505. $frs = m('file')->getone($fileid);
  506. if(!$frs)return returnerror('不存在');
  507. $lujing = $frs['filepathout'];
  508. if(isempt($lujing)){
  509. $lujing = $frs['filepath'];
  510. if(substr($lujing,0,4)!='http' && !file_exists($lujing))return returnerror('文件不存在了');
  511. }
  512. $fileext = $frs['fileext'];
  513. $fname = $this->jm->base64decode($this->get('fname'));
  514. $fname = (isempt($fname)) ? $frs['filename'] : ''.$fname.'.'.$fileext.'';
  515. $filepath = ''.UPDIR.'/'.date('Y-m').'/'.date('d').'_rocktpl'.rand(1000,9999).'_'.$fileid.'.'.$fileext.'';
  516. $this->rock->createtxt($filepath, file_get_contents($lujing));
  517. $uarr = array(
  518. 'filename' => $this->rock->xssrepstr($fname),
  519. 'fileext' => $fileext,
  520. 'filepath' => $filepath,
  521. 'filesize' => filesize($filepath),
  522. 'filesizecn' => $this->rock->formatsize(filesize($filepath)),
  523. 'optid' => $this->adminid,
  524. 'optname' => $this->adminname,
  525. 'adddt' => $this->rock->now,
  526. 'ip' => $this->rock->ip,
  527. 'web' => $this->rock->web,
  528. );
  529. $uarr['id'] = m('file')->insert($uarr);
  530. return returnsuccess($uarr);
  531. }
  532. /**
  533. * 文库选择文件
  534. */
  535. public function changedataAction()
  536. {
  537. $rows = array();
  538. $uptp = $this->get('uptp');
  539. $tsye = $this->get('tsye');
  540. $key = $this->get('key');
  541. $selv = (int)$this->get('selvalue','0');
  542. $where = '`optid`='.$this->adminid.'';
  543. if($selv==1){
  544. $str = m('admin')->getjoinstrs('`shateid`', $this->adminid, 1);
  545. $where = '`id` in(select `fileid` from `[Q]word` where `type`=0 '.$str.' )';
  546. }
  547. if($key){
  548. $key = $this->rock->xssrepstr($this->jm->base64decode($key));
  549. $where.=" and `filename` like '%".$key."%'";
  550. }
  551. if($uptp && $uptp!='*'){
  552. if($uptp=='image')$uptp='jpg,png,gif,jpeg';
  553. $uptp = str_replace(',', "','", $uptp);
  554. $where.=" and `fileext` in('".$uptp."')";
  555. }
  556. $db = m('file');
  557. $rows = $db->getall($where,'id,filename,filesizecn,fileext,thumbpath,thumbplat,filepath,filepathout','`id` desc limit 10');
  558. foreach($rows as $k=>$rs){
  559. $rows[$k]['value'] = $rs['id'];
  560. $rows[$k]['name'] = $rs['filename'];
  561. $rows[$k]['subname']= $rs['filesizecn'];
  562. $rows[$k]['xuanbool']= true;
  563. if($tsye=='img'){
  564. if(!isempt($rs['filepathout']))$rows[$k]['filepath'] = $rs['filepathout'];
  565. }else{
  566. unset($rows[$k]['filepath']);
  567. }
  568. unset($rows[$k]['filepathout']);
  569. if(!isempt($rs['thumbpath'])){
  570. $rows[$k]['iconsimg'] = $rs['thumbpath'];
  571. if(!isempt($rs['thumbplat']))$rows[$k]['iconsimg'] = $rs['thumbplat'];
  572. }else{
  573. $flx = $rs['fileext'];
  574. if(!contain($db->fileall,','.$flx.','))$flx='wz';
  575. $rows[$k]['iconsimg'] = 'web/images/fileicons/'.$flx.'.gif';
  576. }
  577. }
  578. $count = $db->rows($where);
  579. $selectdata[] = array('value'=>'','name'=>'选自己上传');
  580. $selectdata[] = array('value'=>'1','name'=>'共享给我的');
  581. return array(
  582. 'rows' => $rows,
  583. 'totalCount' => $count,
  584. 'selectdata' => $selectdata
  585. );
  586. }
  587. /**
  588. * 20250522更新修改
  589. */
  590. private $upsize = 154857;
  591. public function officeexistsAction()
  592. {
  593. $id = (int)$this->get('id');
  594. $otype = (int)$this->get('otype'); //0编辑1预览
  595. $frs = m('file')->getone($id);
  596. if(!$frs)return returnerror('文件不存在0');
  597. $onlynum = $frs['onlynum'];
  598. if(isempt($onlynum)){
  599. $onlynum = md5(''.$this->rock->jm->getRandkey().date('YmdHis').'file'.$id.'');
  600. m('file')->update("`onlynum`='$onlynum'", $id);
  601. }
  602. $path = $this->getfurls($frs);
  603. if(isempt($path))return returnerror('文件不存在1');
  604. $obj = c('rockedit');
  605. $urs = m('admin')->getone($this->adminid);
  606. $barr = $obj->getdata('file','change', array(
  607. 'filenum' => $onlynum,
  608. 'optid' => $this->adminid,
  609. 'otype' => $otype,
  610. 'fileext' => $frs['fileext'],
  611. 'erand' => $this->get('erand'),
  612. 'filename' => $this->rock->jm->base64encode($frs['filename']),
  613. 'optname' => $this->rock->jm->base64encode($this->adminname),
  614. 'face' => $this->rock->jm->base64encode(m('admin')->getface($urs['face'])),
  615. ));
  616. if(!$barr['success'])return $barr;
  617. $da = $barr['data'];
  618. if($da['type']==0){
  619. $barr['data']['filesizecn'] = $frs['filesizecn'];
  620. $barr['data']['fileext'] = $frs['fileext'];
  621. $barr['data']['fileid'] = $id;
  622. if(substr($path,0,4)=='http'){
  623. $zong = 1;
  624. }else{
  625. $filesize = filesize($path);
  626. $zong = ceil($filesize/$this->upsize);
  627. if($zong<=0)$zong = 1;
  628. }
  629. $barr['data']['zong'] = $zong;
  630. }else{
  631. $barr['data']['url'] = $obj->gotourl($da['gourl'],$da['gokey'],$onlynum, $otype, $this->admintoken, $id);
  632. }
  633. return $barr;
  634. }
  635. public function getfurls($frs)
  636. {
  637. $filepath = $frs['filepath'];
  638. if(file_exists($filepath))return $filepath;
  639. $path = $frs['filepathout'];
  640. if(isempt($path))$path = $filepath;
  641. if(substr($path,0,4)=='http')return $path;
  642. if(!file_exists($path))return '';
  643. return $path;
  644. }
  645. //开始上传
  646. public function officefstartAction()
  647. {
  648. $id = (int)$this->get('id');
  649. $zong = (int)$this->get('zong');
  650. $ci = (int)$this->get('ci');
  651. $otype = (int)$this->get('otype');
  652. $filemid = (int)$this->get('filemid');
  653. $frs = m('file')->getone($id);
  654. $path = $this->getfurls($frs);
  655. $conts = '';
  656. $datype = 'base';
  657. if(substr($path,0,4)=='http'){
  658. $datype = 'http';
  659. $conts = $path; //http远程地址的
  660. }else{
  661. $fp = @fopen($path,'rb');
  662. if(!$fp)return returnerror('无法读取文件');
  663. $oi = 0;
  664. while(!feof($fp)){
  665. $cont = fread($fp, $this->upsize);
  666. if($oi==$ci){
  667. $conts = $cont;
  668. break;
  669. }
  670. $oi++;
  671. }
  672. fclose ($fp);
  673. }
  674. $obj = c('rockedit');
  675. $barr = $obj->postdata('file','fstart', array(
  676. 'filenum' => $frs['onlynum'],
  677. 'data' => $this->rock->jm->base64encode($conts),
  678. 'zong' => $zong,
  679. 'datype' => $datype,
  680. 'ci' => $ci,
  681. 'fileid' => $id,
  682. 'filemid' => $filemid,
  683. 'filesize' => $frs['filesize'],
  684. 'fileext' => $frs['fileext'],
  685. 'filename' => $this->rock->jm->base64encode($frs['filename']),
  686. ));
  687. if(!$barr['success'])return $barr;
  688. $bda = $barr['data'];
  689. if($bda['result']=='ok'){
  690. $gokey = $this->get('gokey');
  691. $gourl = $this->rock->jm->base64decode($this->get('gourl'));
  692. $barr['data']['url'] = $obj->gotourl($gourl,$gokey,$frs['onlynum'], $otype, $this->admintoken, $id);;
  693. }
  694. return $barr;
  695. }
  696. }
粤ICP备19079148号