File.php 1.3 KB

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