Laravel - 로컬디스크 파일업로드 시 유의사항 > IT 기술백서

IT 기술백서

직접 알아내거나 검색하기 귀찮아서 모아 둔 것

php | Laravel - 로컬디스크 파일업로드 시 유의사항

본문

/config/filesystems.php

 

[code]

'disk' => [

    'driver' => 'local',

    'root' => storage_path('app/public'),  // 기본은 'app' 으로 되어 있다.

]

[/code]

 

/storage/app/public 을 /public/storage 로 심볼릭링크 하였다면

업로드 root 디렉토리를 'app' 을 'app/public' 으로 해줘야 url이 꼬이지 않는다.

 

업로드 예


[code]

 

$request->validate([

    'photo' => ['required', 'file', 'mimes:jpeg,jpg,gif,png']

]);


$path = $request->file('photo')->store('profile');


return response()->json([

    'path' => asset('/storage/'.$path) // http://... 와 같이 full url 을 리턴해 준다.

]);

[/code]

댓글 0개

등록된 댓글이 없습니다.

Menu