본문 바로가기
개발자 커뮤니티에 오신 것을 환영합니다!

PHP [PHP] base64 이미지 전송받아 png로 저장하기

페이지 정보

profile_image
작성자 하나를하더라도최선을
댓글 0건 조회 15,275회 작성일 20-02-27 22:06

본문

<?
    if(isset($_POST['submit'])){
        define('UPLOAD_DIR''img/');
 
        $img = $_POST['image'];
 
        $img = str_replace('data:image/png;base64,'''$img);
        $img = str_replace(' ''+'$img);
        $data = base64_decode($img);
        $file = UPLOAD_DIR . uniqid() . '.png';
        $success = file_put_contents($file$data);
 
        print $success ? $file : 'Unable to save the file.';
    }        
?>
 
    <form method="post"  name="change" enctype="multipart-form/data">
 
        <!-- <img src="" id="img" name="image" >  -->
        <input type="text" name="image" id="img" hidden="hidden" value="base64Code">
 
        <input type="submit" name="submit">
 
    </form>
 

댓글목록

등록된 댓글이 없습니다.


Copyright © program1472 | IT HUB. All rights reserved.