File.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\h5\controller;
  3. use think\captcha\Captcha;
  4. use think\Controller;
  5. use app\hander\HelpHander;
  6. class File extends Controller
  7. {
  8. public function upfile(){
  9. $file = request()->file('files');
  10. // 移动到框架应用根目录/uploads/ 目录下
  11. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  12. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  13. if($info){
  14. $img = '/uploads/files/' . $info->getSaveName();
  15. $img = str_replace('\\', '/', $img);
  16. $path = request()->domain(true).$img;
  17. HelpHander::success(['path' => $path]);
  18. }else{
  19. HelpHander::error($file->getError());
  20. }
  21. }
  22. public function upimg(){
  23. $file = request()->file('files');
  24. // 移动到框架应用根目录/uploads/ 目录下
  25. $info = $file->validate(config('app.max_upload_img'))
  26. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  27. if($info){
  28. $img = '/uploads/files/' . $info->getSaveName();
  29. $img = str_replace('\\', '/', $img);
  30. $path = request()->domain(true).$img;
  31. HelpHander::success(['path' => $path]);
  32. }else{
  33. HelpHander::error($file->getError());
  34. }
  35. }
  36. }