uploadAction.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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. $filesize = c('check')->onlynumber($this->post('filesize'));
  166. $fileext = $this->post('fileext');
  167. $filename = $this->getvals('filename');
  168. $where = "`fileext`='$fileext' and `filesize`='$filesize'";
  169. if(!isempt($filename))$where.=" and `filename`='$filename'";
  170. $frs = m('file')->getone($where,'*','`id` desc');
  171. $bo = false;
  172. if($frs){
  173. $filepath = $frs['filepath'];
  174. if(!isempt($filepath) && file_exists($filepath))$bo=true;
  175. }
  176. if($bo){
  177. $this->showreturn(json_encode($frs));
  178. }else{
  179. $this->showreturn('','not found', 201);
  180. }
  181. }
  182. public function upfileappAction()
  183. {
  184. if(!$_FILES)$this->showreturn('', '禁止访问', 201);
  185. $upimg = c('upfile');
  186. $maxsize= (int)$this->get('maxsize', $upimg->getmaxzhao());//上传最大M
  187. $uptypes= '*';
  188. $upimg->initupfile($uptypes, ''.UPDIR.'|reimchat|'.date('Y-m').'', $maxsize);
  189. $upses = $upimg->up('file');
  190. if(!is_array($upses))$this->showreturn('', $upses, 202);
  191. $arr = c('down')->uploadback($upses);
  192. $this->showreturn($arr);
  193. }
  194. public function upcontAction()
  195. {
  196. $cont = $this->post('content');
  197. if(isempt($cont))exit('sorry not cont');
  198. $cont = str_replace(' ','', $cont);
  199. $cont = $this->rock->jm->base64decode($cont);
  200. $arr = c('down')->createimage($cont,'png','截图');
  201. $this->returnjson($arr);
  202. }
  203. public function getfileAjax()
  204. {
  205. $cont = '';
  206. $path = ''.UPDIR.'/uptxt'.$this->adminid.'.txt';
  207. if(file_exists($path)){
  208. @$cont = file_get_contents($path);
  209. }
  210. $data = array();
  211. if($cont!=''){
  212. $arr = json_decode($cont, true);
  213. $msg = $arr['msg'];
  214. $data = $arr['data'];
  215. @unlink($path);
  216. }else{
  217. $msg = 'sorry,not infor!';
  218. }
  219. $this->showreturn($data, $msg);
  220. }
  221. public function getfileAction()
  222. {
  223. $fileid = (int)$this->post('fileid',0);
  224. $rs = m('file')->getone($fileid);
  225. $this->showreturn($rs);
  226. }
  227. public function downAction()
  228. {
  229. $id = (int)$this->jm->gettoken('id');
  230. m('file')->show($id);
  231. }
  232. //记录预览记录
  233. public function logsAction()
  234. {
  235. $fileid = (int)$this->post('fileid',0);
  236. $type = (int)$this->post('type',0);
  237. m('file')->addlogs($fileid, $type);
  238. }
  239. /**
  240. * 发送编辑权限
  241. */
  242. public function rockofficeeditAction()
  243. {
  244. $fileid = (int)$this->get('id');
  245. $lx = (int)$this->get('lx');
  246. $frs = m('file')->getone($fileid);
  247. if(!$frs)return returnerror('文件不存在了');
  248. $filepath = $frs['filepath'];
  249. $filepathout = $frs['filepathout'];
  250. if(substr($filepath,0,4)!='http' && !file_exists($filepath)){
  251. if(isempt($filepathout)){
  252. return returnerror('文件不存在了1');
  253. }else{
  254. $filepath = $filepathout;
  255. }
  256. }
  257. $uptype = '|doc|docx|xls|xlsx|ppt|pptx|';
  258. if(!contain($uptype,'|'.$frs['fileext'].'|'))return returnerror('不是文档类型无法在线编辑');
  259. $filename = $frs['filename'];
  260. $utes = 'edit';
  261. if($lx==1){
  262. $filename = '(只读)'.$filename.'';
  263. $utes = 'yulan';
  264. }
  265. $arr = array();
  266. $arr[0] = URL;
  267. $arr[1] = $filename;
  268. $arr[2] = $this->createtempurl($frs);
  269. $arr[3] = $this->rock->gethttppath($filepath); //下载地址
  270. $arr[4] = $fileid;
  271. $arr[5] = $this->adminid;
  272. $arr[6] = $this->token;
  273. $arr[7] = $utes;
  274. $arr[8] = $frs['fileext'];
  275. $str = '';
  276. foreach($arr as $s1)$str.=','.$s1.'';
  277. return returnsuccess(substr($str,1));
  278. }
  279. /**
  280. * 获取预览和下载地址
  281. */
  282. public function fileinfoAction()
  283. {
  284. $fileid = (int)$this->get('id');
  285. $type = (int)$this->get('type'); //0预览,1下载,2编辑
  286. $ismobile = (int)$this->get('ismobile'); //是否手机端
  287. return $this->fileinfoShow($fileid, $type, $ismobile);
  288. }
  289. private $frs,$loadyuan;
  290. public function fileinfoShow($fileid, $type, $ismobile)
  291. {
  292. $fobj = m('file');
  293. $frs = $fobj->getone($fileid);
  294. $this->frs = $frs;
  295. if(!$frs)return returnerror('文件不存在了');
  296. $filenum= $frs['filenum'];
  297. $fileext = $frs['fileext'];
  298. $filename = $frs['filename'];
  299. $filepath = $frs['filepath'];
  300. $filepathout = arrvalue($frs, 'filepathout');
  301. $data = array();
  302. $loadyuan = false;
  303. $data['url'] = '';
  304. $data['fileext']= $fileext;
  305. //预览
  306. if($type==0){
  307. if(!$fobj->isview($fileext))
  308. return returnerror('此'.$fileext.'类型文件不支持在线预览');
  309. }
  310. //从文件上传中心最新
  311. if(!isempt($filenum)){
  312. $dbs = m('admin');
  313. $barr = c('rockfile')->getdata('upload','fileinfo', array(
  314. 'fnum' => $filenum,
  315. 'lx' => $type,
  316. 'sysuid' => $this->adminid,
  317. 'ismobile' => $ismobile,
  318. 'sysname' => $this->rock->jm->base64encode($this->adminname),
  319. 'sysface' => $this->rock->jm->base64encode($dbs->getface($dbs->getmou('face',$this->adminid))),
  320. ));
  321. if(!$barr['success']){
  322. return $barr;
  323. }else{
  324. $loadyuan = true;
  325. $da = $barr['data'];
  326. $data['url'] = $da['url'];
  327. if($da['isimg'] && $type==0)$data['url'] = $da['imgurl'];
  328. }
  329. }
  330. $this->loadyuan = $loadyuan;
  331. //存自己服务器的
  332. if(!$loadyuan){
  333. if(substr($filepath,0,4)!='http' && isempt($filepathout) && !file_exists($filepath))return returnerror('文件不存在了1');
  334. if(c('upfile')->isimg($fileext)){
  335. $data['url'] = m('admin')->getface($filepath);
  336. if(!isempt($filepathout))$data['url'] = $filepathout;
  337. }
  338. //下载
  339. if($type==1){
  340. $url = 'api.php?m=upload&id='.$fileid.'&a=down';
  341. if($this->rock->web=='wxbro')$url.= '&adminid='.$this->adminid.'&token='.$this->admintoken.'';
  342. $data['url'] = $url;
  343. }
  344. //编辑
  345. if($type==2){
  346. if(getconfig('officebj')=='1'){
  347. $erand = rand(1000000,9999999);
  348. $data['fileext']= 'rockedit';
  349. $data['url'] = 'index.php?m=public&a=fileedit&id='.$fileid.'&erand='.$erand.'';
  350. $data['editwsinfo'] = c('rockedit')->getwsinfo(array(
  351. 'erand' => $erand,
  352. 'fileid'=> $fileid
  353. ));
  354. /*
  355. c('rockqueue')->push('rockoffice,gedit', array(
  356. 'erand' => $erand,
  357. 'cishu' =>1,
  358. 'fileid' =>$fileid,
  359. 'optid' => $this->adminid
  360. ), time() + 10);*/
  361. }else{
  362. if($ismobile==1)return returnerror('移动端不支持在线编辑');
  363. $data['fileext']='rockoffice';
  364. $data['url'] = $this->rock->gethttppath($filepath);
  365. }
  366. }
  367. }
  368. $data['filename'] = $filename;
  369. $url = arrvalue($data, 'url');
  370. if($url==''){
  371. $url = 'index.php?m=public&a=fileviewer&id='.$fileid.'';
  372. }
  373. //用本地插件编辑和预览
  374. if($data['fileext']=='rockoffice'){
  375. $utes = 'edit';
  376. if($type==0){
  377. $filename = '(只读)'.$filename.'';
  378. $utes = 'yulan';
  379. }
  380. $arr = array();
  381. $arr[0] = URL;
  382. $arr[1] = $filename;
  383. $arr[2] = $this->createtempurl($frs);
  384. $arr[3] = $data['url']; //下载地址
  385. $arr[4] = $fileid;
  386. $arr[5] = $this->adminid;
  387. $arr[6] = $this->token;
  388. $arr[7] = $utes;
  389. $arr[8] = $fileext;
  390. $str = '';
  391. foreach($arr as $s1)$str.=','.$s1.'';
  392. $url = substr($str, 1);
  393. }
  394. $data['url'] = $url;
  395. $data['type'] = $type;
  396. $data['id'] = $fileid;
  397. $data['isview'] = $fobj->isview($fileext); //是否可直接预览
  398. return returnsuccess($data);
  399. }
  400. //生成唯一文件名键值
  401. private function createtempurl($frs)
  402. {
  403. $str = ''.md5(URL).'_'.$frs['filesize'].'_'.$frs['id'].'.'.$frs['fileext'].'';
  404. return $str;
  405. }
  406. /**
  407. * app上获取下载地址
  408. */
  409. public function appgetfileAction()
  410. {
  411. $id = (int)$this->post('id',0);
  412. $barr = $this->fileinfoShow($id, 1, 1);
  413. if(!$barr['success'])return $barr;
  414. $frs = $this->frs;
  415. $frs['filetype'] = m('file')->getmime($frs['fileext']);
  416. $frs['downurl'] = $barr['data']['url'].'&cfrom=app';
  417. if(!$this->loadyuan){
  418. $frs['downurl']= '';
  419. if(substr($frs['filepath'],0,4)=='http'){
  420. $frs['downurl'] = $frs['filepath'];
  421. }else{
  422. if(!file_exists($frs['filepath']) && arrvalue($frs,'filepathout'))$frs['downurl'] = $frs['filepathout'];
  423. }
  424. }
  425. return returnsuccess($frs);
  426. }
  427. /**
  428. * 编辑时验证
  429. */
  430. public function sendeditAction()
  431. {
  432. $id = (int)$this->get('id',0);
  433. $otype = (int)$this->get('otype',0);
  434. return c('rockedit')->sendedit($id, $this->admintoken, $otype);
  435. }
  436. /**
  437. * 获取文件信息
  438. */
  439. public function afileinfoAction()
  440. {
  441. $allfid = c('check')->onlynumber($this->get('allfid'));
  442. $filearr= array();
  443. if($allfid){
  444. $fobj = m('file');
  445. $frows = $fobj->getall('`id` in('.$allfid.')','filename,id,filesizecn,fileext,optname,thumbpath,thumbplat');
  446. foreach($frows as $k1=>$rs1){
  447. $rs1['thumbpath'] = $fobj->getthumbpath($rs1);
  448. $filearr['f'.$rs1['id'].''] = $rs1;
  449. }
  450. }
  451. return $filearr;
  452. }
  453. /**
  454. * 获取文件(写入到内容里)
  455. */
  456. public function filedaoAction()
  457. {
  458. $allfid = c('check')->onlynumber($this->get('fileid'));
  459. $filearr= array();
  460. $str = '';
  461. if($allfid){
  462. $fobj = m('file');
  463. $frows = $fobj->getall('`id` in('.$allfid.')');
  464. $urla = getconfig('outurl', URL);
  465. foreach($frows as $k1=>$rs1){
  466. $str.='<br>';
  467. $url = ''.$urla.''.$rs1['filepath'].'';
  468. if($sst = arrvalue($rs1,'filepathout'))$url = $sst;
  469. $flx = $rs1['fileext'];
  470. if(!contain($fobj->fileall,','.$flx.','))$flx='wz';
  471. $str1 = '';
  472. $imurl = ''.URL.'web/images/fileicons/'.$flx.'.gif';
  473. $thumbpath = $fobj->getthumbpath($rs1);
  474. if($fobj->isimg($flx) && !isempt($thumbpath))$imurl = $thumbpath;
  475. $str.='<img src="'.$imurl.'" align="absmiddle" height=20 width=20> <a target="_blank" href="'.$url.'">'.$rs1['filename'].'</a>('.$rs1['filesizecn'].')';
  476. }
  477. }
  478. return $str;
  479. }
  480. /**
  481. * 获取模版文件
  482. */
  483. public function getmfileAction()
  484. {
  485. $data = array();
  486. $fenlei = $this->jm->base64decode($this->get('fenlei'));
  487. $fenlei = $this->rock->xssrepstr($this->rock->iconvsql($fenlei));
  488. $where = m('admin')->getjoinstr('a.`receid`', $this->adminid, 1);
  489. $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.')';
  490. $rows = $this->db->getall($sql);
  491. foreach($rows as $k=>$rs){
  492. $data[] = array(
  493. 'value' => $rs['id'],
  494. 'name' => $rs['name'],
  495. 'subname' => $rs['wtype'],
  496. );
  497. }
  498. return $data;
  499. }
  500. public function getmfilvAction()
  501. {
  502. $fileid = (int)$this->get('fileid','0');
  503. $frs = m('file')->getone($fileid);
  504. if(!$frs)return returnerror('不存在');
  505. $lujing = $frs['filepathout'];
  506. if(isempt($lujing)){
  507. $lujing = $frs['filepath'];
  508. if(substr($lujing,0,4)!='http' && !file_exists($lujing))return returnerror('文件不存在了');
  509. }
  510. $fileext = $frs['fileext'];
  511. $fname = $this->jm->base64decode($this->get('fname'));
  512. $fname = (isempt($fname)) ? $frs['filename'] : ''.$fname.'.'.$fileext.'';
  513. $filepath = ''.UPDIR.'/'.date('Y-m').'/'.date('d').'_rocktpl'.rand(1000,9999).'_'.$fileid.'.'.$fileext.'';
  514. $this->rock->createtxt($filepath, file_get_contents($lujing));
  515. $uarr = array(
  516. 'filename' => $this->rock->xssrepstr($fname),
  517. 'fileext' => $fileext,
  518. 'filepath' => $filepath,
  519. 'filesize' => filesize($filepath),
  520. 'filesizecn' => $this->rock->formatsize(filesize($filepath)),
  521. 'optid' => $this->adminid,
  522. 'optname' => $this->adminname,
  523. 'adddt' => $this->rock->now,
  524. 'ip' => $this->rock->ip,
  525. 'web' => $this->rock->web,
  526. );
  527. $uarr['id'] = m('file')->insert($uarr);
  528. return returnsuccess($uarr);
  529. }
  530. /**
  531. * 文库选择文件
  532. */
  533. public function changedataAction()
  534. {
  535. $rows = array();
  536. $uptp = $this->get('uptp');
  537. $tsye = $this->get('tsye');
  538. $key = $this->get('key');
  539. $selv = (int)$this->get('selvalue','0');
  540. $where = '`optid`='.$this->adminid.'';
  541. if($selv==1){
  542. $str = m('admin')->getjoinstrs('`shateid`', $this->adminid, 1);
  543. $where = '`id` in(select `fileid` from `[Q]word` where `type`=0 '.$str.' )';
  544. }
  545. if($key){
  546. $key = $this->rock->xssrepstr($this->jm->base64decode($key));
  547. $where.=" and `filename` like '%".$key."%'";
  548. }
  549. if($uptp && $uptp!='*'){
  550. if($uptp=='image')$uptp='jpg,png,gif,jpeg';
  551. $uptp = str_replace(',', "','", $uptp);
  552. $where.=" and `fileext` in('".$uptp."')";
  553. }
  554. $db = m('file');
  555. $rows = $db->getall($where,'id,filename,filesizecn,fileext,thumbpath,thumbplat,filepath,filepathout','`id` desc limit 10');
  556. foreach($rows as $k=>$rs){
  557. $rows[$k]['value'] = $rs['id'];
  558. $rows[$k]['name'] = $rs['filename'];
  559. $rows[$k]['subname']= $rs['filesizecn'];
  560. $rows[$k]['xuanbool']= true;
  561. if($tsye=='img'){
  562. if(!isempt($rs['filepathout']))$rows[$k]['filepath'] = $rs['filepathout'];
  563. }else{
  564. unset($rows[$k]['filepath']);
  565. }
  566. unset($rows[$k]['filepathout']);
  567. if(!isempt($rs['thumbpath'])){
  568. $rows[$k]['iconsimg'] = $rs['thumbpath'];
  569. if(!isempt($rs['thumbplat']))$rows[$k]['iconsimg'] = $rs['thumbplat'];
  570. }else{
  571. $flx = $rs['fileext'];
  572. if(!contain($db->fileall,','.$flx.','))$flx='wz';
  573. $rows[$k]['iconsimg'] = 'web/images/fileicons/'.$flx.'.gif';
  574. }
  575. }
  576. $count = $db->rows($where);
  577. $selectdata[] = array('value'=>'','name'=>'选自己上传');
  578. $selectdata[] = array('value'=>'1','name'=>'共享给我的');
  579. return array(
  580. 'rows' => $rows,
  581. 'totalCount' => $count,
  582. 'selectdata' => $selectdata
  583. );
  584. }
  585. /**
  586. * 20250522更新修改
  587. */
  588. private $upsize = 154857;
  589. public function officeexistsAction()
  590. {
  591. $id = (int)$this->get('id');
  592. $otype = (int)$this->get('otype'); //0编辑1预览
  593. $frs = m('file')->getone($id);
  594. if(!$frs)return returnerror('文件不存在0');
  595. $onlynum = $frs['onlynum'];
  596. if(isempt($onlynum)){
  597. $onlynum = md5(''.$this->rock->jm->getRandkey().date('YmdHis').'file'.$id.'');
  598. m('file')->update("`onlynum`='$onlynum'", $id);
  599. }
  600. $path = $this->getfurls($frs);
  601. if(isempt($path))return returnerror('文件不存在1');
  602. $obj = c('rockedit');
  603. $urs = m('admin')->getone($this->adminid);
  604. $barr = $obj->getdata('file','change', array(
  605. 'filenum' => $onlynum,
  606. 'optid' => $this->adminid,
  607. 'otype' => $otype,
  608. 'fileext' => $frs['fileext'],
  609. 'erand' => $this->get('erand'),
  610. 'filename' => $this->rock->jm->base64encode($frs['filename']),
  611. 'optname' => $this->rock->jm->base64encode($this->adminname),
  612. 'face' => $this->rock->jm->base64encode(m('admin')->getface($urs['face'])),
  613. ));
  614. if(!$barr['success'])return $barr;
  615. $da = $barr['data'];
  616. if($da['type']==0){
  617. $barr['data']['filesizecn'] = $frs['filesizecn'];
  618. $barr['data']['fileext'] = $frs['fileext'];
  619. $barr['data']['fileid'] = $id;
  620. if(substr($path,0,4)=='http'){
  621. $zong = 1;
  622. }else{
  623. $filesize = filesize($path);
  624. $zong = ceil($filesize/$this->upsize);
  625. if($zong<=0)$zong = 1;
  626. }
  627. $barr['data']['zong'] = $zong;
  628. }else{
  629. $barr['data']['url'] = $obj->gotourl($da['gourl'],$da['gokey'],$onlynum, $otype, $this->admintoken, $id);
  630. }
  631. return $barr;
  632. }
  633. public function getfurls($frs)
  634. {
  635. $filepath = $frs['filepath'];
  636. if(file_exists($filepath))return $filepath;
  637. $path = $frs['filepathout'];
  638. if(isempt($path))$path = $filepath;
  639. if(substr($path,0,4)=='http')return $path;
  640. if(!file_exists($path))return '';
  641. return $path;
  642. }
  643. //开始上传
  644. public function officefstartAction()
  645. {
  646. $id = (int)$this->get('id');
  647. $zong = (int)$this->get('zong');
  648. $ci = (int)$this->get('ci');
  649. $otype = (int)$this->get('otype');
  650. $filemid = (int)$this->get('filemid');
  651. $frs = m('file')->getone($id);
  652. $path = $this->getfurls($frs);
  653. $conts = '';
  654. $datype = 'base';
  655. if(substr($path,0,4)=='http'){
  656. $datype = 'http';
  657. $conts = $path; //http远程地址的
  658. }else{
  659. $fp = @fopen($path,'rb');
  660. if(!$fp)return returnerror('无法读取文件');
  661. $oi = 0;
  662. while(!feof($fp)){
  663. $cont = fread($fp, $this->upsize);
  664. if($oi==$ci){
  665. $conts = $cont;
  666. break;
  667. }
  668. $oi++;
  669. }
  670. fclose ($fp);
  671. }
  672. $obj = c('rockedit');
  673. $barr = $obj->postdata('file','fstart', array(
  674. 'filenum' => $frs['onlynum'],
  675. 'data' => $this->rock->jm->base64encode($conts),
  676. 'zong' => $zong,
  677. 'datype' => $datype,
  678. 'ci' => $ci,
  679. 'fileid' => $id,
  680. 'filemid' => $filemid,
  681. 'filesize' => $frs['filesize'],
  682. 'fileext' => $frs['fileext'],
  683. 'filename' => $this->rock->jm->base64encode($frs['filename']),
  684. ));
  685. if(!$barr['success'])return $barr;
  686. $bda = $barr['data'];
  687. if($bda['result']=='ok'){
  688. $gokey = $this->get('gokey');
  689. $gourl = $this->rock->jm->base64decode($this->get('gourl'));
  690. $barr['data']['url'] = $obj->gotourl($gourl,$gokey,$frs['onlynum'], $otype, $this->admintoken, $id);;
  691. }
  692. return $barr;
  693. }
  694. }
粤ICP备19079148号