fileAction.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * 文件下载相关接口-用于app
  4. */
  5. class fileClassAction extends apiAction
  6. {
  7. /**
  8. * 获取文件信息
  9. */
  10. public function getfileAction()
  11. {
  12. $id = (int)$this->post('id',0);
  13. $rs = m('file')->getone($id);
  14. if(!$rs)$this->showreturn('', '文件不存在1', 201);
  15. $path = $rs['filepath'];
  16. if(isempt($path) || !file_exists($path))$this->showreturn('', '文件['.$rs['filename'].']不存在', 202);
  17. $rs['filetype'] = m('file')->getmime($rs['fileext']);
  18. $this->showreturn($rs);
  19. }
  20. /**
  21. * 下载文件
  22. */
  23. public function downAction()
  24. {
  25. $id = (int)$this->jm->gettoken('id');
  26. m('file')->show($id);
  27. }
  28. /**
  29. * 获取文件信息
  30. */
  31. public function getfilenewAction()
  32. {
  33. $id = (int)$this->post('id',0);
  34. $rs = m('file')->getone($id);
  35. if(!$rs)$this->showreturn('', '文件不存在1', 201);
  36. $path = $rs['filepath'];
  37. if(isempt($rs['filenum'])){
  38. if(substr($path,0,4)!='http' && !file_exists($path))
  39. $this->showreturn('', '文件['.$rs['filename'].']不存了', 202);
  40. }
  41. $rs['filetype'] = m('file')->getmime($rs['fileext']);
  42. $rs['downurl'] = '';
  43. $this->showreturn($rs);
  44. }
  45. }