PHP를 위한 S3 SDK : 웹애플리케이션에서 S3 활용
undefined undefined
PHP를 위한 S3 SDK : 웹애플리케이션에서 S3 활용

업로드 폼

upload.html

1
2
3
4
5
6
7
8
<html>
<body>
<form enctype="multipart/form-data" action="./s3_upload.php" method="POST">
<input type="file" name="userfile">
<input type="submit">
</form>
</body>
</html>

s3로 파일 전송

s3_upload.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
require 'vendor/autoload.php';
$param = Array('region'=>'ap-northeast-2', 'version'=>'2006-03-01');
$s3 = new Aws\S3\S3Client($param);
$result = $s3->putObject(Array(
'ACL'=>'public-read',
'SourceFile'=>$_FILES['userfile']['tmp_name'],
'Bucket'=>'codingeverybody2',
'Key'=>$_FILES['userfile']['name'],
'ContentType'=>$_FILES['userfile']['type']
));
unlink($_FILES['userfile']['tmp_name']);
$resultArray = $result->toArray();
var_dump($resultArray['ObjectURL']);
?>
<html>
<body>
<img src="<?php print($resultArray['ObjectURL']);?>" style="width:100%">
</body>
</html>
질문하기
추가 자료
no files uploaded

추가 자료가 없습니다

여기서 새로운 학습 자료를 확인하세요!
선생님이 추가한 자료들을 바로 확인할 수 있어요.