- PHP Laravel use AWS sdk
1) S3용 IAM 계정 추가
- .ENV 파일에 정보 추가
AWS_SECRET 은 액세스 키를 만들때 만 볼수 있다.
AWS_KEY=
AWS_SECRET=
2) 라라벨 S3용 패키지 설치
composer require league/flysystem-aws-s3-v3
- config/filesystems.php 파일 설정 확인
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
...
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
3) 복사, 삭제, 이동, 이름변경
Storage::disk('s3')->put('tmp/'.$file, file_get_contents($file) );//추가
Storage::disk('s3')->delete('tmp/' . $file);//삭제
Storage::disk('s3')->files('tmp');//리스트
Storage::disk('s3')->get($file);//내용
Storage::disk('s3')->url($file);//인터넷 주소
Storage::size('file1.jpg');//크기 조회
Storage::copy('old/file1.jpg', 'new/file1.jpg');//복사
Storage::move('old/file1.jpg', 'new/file1.jpg');//이동
Storage::files($directory);//파일 목록
Storage::allFiles($directory);//하위 폴더 포함
Storage::directories($directory);//폴더 목록
Storage::allDirectories($directory);
Storage::makeDirectory($directory);//폴더 만들기
Storage::deleteDirectory($directory);//폴더 삭제
//==============
//참고
http://stayregular.net/blog/how-to-upload-images-using-amazon-s3-and-laravel
https://dzone.com/articles/how-to-upload-files-to-amazon-s3-using-laravel
'Code > PHP' 카테고리의 다른 글
[php] 이벤트 라이브러리 (0) | 2019.08.09 |
---|---|
[라라벨] 서버 다운 메시지 변경 (0) | 2019.08.04 |
라라벨에서 AWS S3 사용하기 (0) | 2019.07.08 |
[PHP] String Complex (curly) syntax (0) | 2019.04.05 |
[PHP] 시간 사용법 (0) | 2019.04.01 |
PHP 7.3으로 업그레이드 (0) | 2019.03.28 |
댓글을 달아 주세요