fileAction.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  46. * 生成水印图片
  47. */
  48. public function shuiyinAction()
  49. {
  50. header("Content-type:image/png");
  51. $font = 'upload/data/simsun.ttc';
  52. if(!file_exists($font))$font = 'C:/Windows/Fonts/simsun.ttc';
  53. $w = 110;
  54. $im = imagecreatetruecolor($w,$w);
  55. $bg = imagecolorallocate($im,255,255,255);
  56. imagefill($im,0,0,$bg); //添加背景颜色
  57. $str = $this->adminname;
  58. //$str = '信呼开发团队'; //改成你要的文字去掉注释
  59. $black = imagecolorallocate($im,220,220,220);
  60. if(file_exists($font)){
  61. imagettftext($im, 14,45, 20, $w-10,$black, $font, $str);
  62. }else{
  63. imagestring($im,5,5, $w-50,$this->adminuser,$black);
  64. }
  65. imagepng($im);
  66. imagedestroy($im);
  67. }
  68. }
粤ICP备19079148号