WAMP/php
file_put_contents( )함수를 이용한 파일 저장
돌크리트
2019. 9. 18. 15:56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
if (preg_match('/^data:image\/(\w+);base64,/', $_POST['file_'.$i], $type)) {
$data = substr($_POST['file_'.$i], strpos($_POST['file_'.$i], ',') + 1);
$type = strtolower($type[1]); // jpg, png, gif
$data = base64_decode($data);
if ($data === false) {
throw new \Exception('base64_decode failed');
}
} else {
throw new \Exception('did not match data URI with image data');
}
$date = date("Ymd");
$file_name = $date."02".$i; // 파일명
$upload_dir = $image_dir.'/images/member/'.$userID.'/'; // 저장 경로
file_put_contents($upload_dir."".$file_name.".{$type}", $data);
|