파일 업로드

Programming/HTML 2017. 12. 12. 10:23

파일 업로드는 업로드하기 위한 컨텐츠다.

 

문법

<input type="file" name="서버쪽에서 파일을 식별하기 위함 이름"/>
enctype="multipart/form-data" 옵션 꼭 지정해줘야됨. 안해주면 파일 전송 안됨.

 

예제

  - uploadexample.html

<!DOCTYPE html>
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
        </head>
        <body>
                <form action="example_receive.php" method="POST" enctype="multipart/form-data">
                    <input type="file" name="image" />
                    <input type="submit" />
                </form>
        </body>
</html>

 

  - example_receive.php

<!DOCTYPE html>
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
        </head>
        <body>
                <?php
                $uploaddir = '/html/';
                $uploadfile = $uploaddir . basename($_FILES['image']['name']);
                move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
                ?>
                <img src="<?=$_FILES['image']['name']?>" />
        </body>
</html>

 

 

'Programming > HTML' 카테고리의 다른 글

URL, 경로  (0) 2017.12.12
체크박스  (0) 2017.12.12
콤보 박스  (0) 2017.12.12
라디오 버튼  (0) 2017.12.11
비밀번호, hidden data, textarea  (0) 2017.12.11
블로그 이미지

꼴통보안인

,