UploadController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Facades\Storage;
  5. use Illuminate\Http\Request;
  6. use App\Repositories\Eloquent\BaseRepository;
  7. /**
  8. *
  9. * @author lilin
  10. *
  11. */
  12. class UploadController extends Controller
  13. {
  14. public function store(Request $request){
  15. $save=array();
  16. $all_file=$request->allFiles();
  17. foreach ($all_file['wangEditorH5File'] as $key => $value) {
  18. if ($value->isValid()) {
  19. $result = '/storage/'.Storage::disk("public")->putFile("editor", $value);
  20. $save[]=config('app.url').$result;
  21. }
  22. }
  23. echo json_encode(array('errno'=>0,'data'=>$save));
  24. }
  25. public function imUploadPic(Request $request)
  26. {
  27. $dst = 'im';
  28. $file = $request->file('file');
  29. $picInfo = getimagesize($file);
  30. if (! $picInfo) {
  31. return self::returnCode('sys.notImageFile');
  32. }
  33. $srcPath = $file->getPathname();
  34. $extension = $file->getClientOriginalExtension();
  35. // $fileName = time() . rand(). '.' . $extension;
  36. $dstPath = $dst . '/' . date('Ym') ;
  37. $path = $request->file('file')->store($dstPath);
  38. return ['code'=>1000, 'data'=>['pic'=>$path]];
  39. }
  40. }