1. 이미지를 업로드시, s3에 저장
- 아래 코드를 /var/www/html/wp-content/themes/sample/functions.php 에 추가
// After media uploaded
add_filter( 'wp_handle_upload', function( $upload, $context ){
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
define( 'S3_KEY', 'S3_KEY');
define( 'S3_SECRET', 'S3_SECRET');
define( 'S3_BUCKET', 'S3_BUCKET');
define( 'S3_REGION', 'ap-northeast-2');
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => S3_REGION,
'credentials' => [
'key' => S3_KEY,
'secret' => S3_SECRET,
]
]);
$file_data = file_get_contents( $upload['file'] );
$file_url = explode('/wp-content/',$upload['url']);
$s3_key = $file_url[1];
$result = $s3->putObject([
'Bucket' => S3_BUCKET,
'Key' => $s3_key,
'Body' => $file_data,
'ACL' => 'public-read'
]);
return $upload;
}, 10, 2);
※ 위 코드는 s3에도 저장만 하는 방법입니다.
아직 작업중이니, 추후에 업데이트 하도록 하겠습니다.
'Programming > WordPress' 카테고리의 다른 글
Wordpress AWS S3와 연동하기 (1편) (0) | 2019.09.30 |
---|---|
WordPress HTTPS 오류 해결 (0) | 2019.07.26 |
WordPress Declaration of selective_Walker::start_el... (0) | 2019.06.12 |
Wordpress Live Server to Local using WAMP (0) | 2019.06.12 |