[Project 2]PHP로 FILE 업로드_ table.php(게시판 작성 양식)
PHP로 FILE 업로드
필요한 파일
- files( 파일이 저장될 파일)
- index.php(파일 리스트)
- delete.php(삭제)
- download.php(파일 다운)
- table.php(게시판 작성 양식)
- write.php(파일이 db에 저장되는 것을 처리)
- view.php(파일의 내용을 볼수 있는 곳)
가장 먼저, 게시판에 데이터를 넣기위한 부분입니다.
table.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <html> <meta charset="utf-8"/> <title>게시판</title> </html> <body> <form action="write.php" method="POST" enctype="multipart/form-data" /> <table align= "center" > <col width=100></col><col width=100></col> <tr> <td>아이디:</td> <td><input type="text" name="id" /></td> </tr> <tr> <td>제목:</td> <td><input type="text" name="subject" /></td> </tr> <tr> <td>내용:</td> <td><textarea name="memo" rows="20"></textarea></td> </tr> <tr> <td>첨부파일:</td> <td><input type="file" id="file" name="file" required /></td> </tr> <tr> <td> <input type="submit" value="전송" /> </td> </tr> </table> </form> </body> </html> | cs |
<form action="write.php" method="POST" enctype="multipart/form-data" />
file을 업로드 하기 위하여 꼭 설정해줘야 하는 부분 enctype="multipart/form-data" 입니다. 꼭!
form 양식의 enctype 은,
<enctype> 1. application/www-form-urlencoded 디폴트값이다. enctype을 따로 설정하지 않으면 이 값이 설정 2. multipart/form-data 파일이나 이미지를 서버로 전송할 경우 3. text/plain 이 형식은 인코딩을 하지 않은 문자 상태로 전송할 경우 |
<table align= "center" >
표를 가운데로 정렬하고 싶다는 의미입니다.
<table align="left|right|center"> 왼쪽|오른쪽|가운데 이렇습니다.
<col width=100></col><col width=100></col>
<col width="pixels|%|relative_length">의 형태로 쓰는데요,
pixels의 경우 : width = "50"
%의 경우 : width = "50%"
relative_length의 경우 : "1*"
사실 저도 이해가 잘 가지 않지만,, 넣어보니 좀더 정리된 기분이 들어.. 넣긴넣었습니다.
더욱 공부하여 올리겠습니다...^^
아이디와 제목의 경우 input type은 text로 받았습니다.
<td><textarea name="memo" rows="20"></textarea></td> 이부분을 보시면,
텍스트 필드가 한줄만 입력할 수 있는것에 비해 텍스트에어리어(textarea)는 여러줄에 걸쳐서 입력할 수 있는 폼 필드입니다.
기본적으로 텍스트에어리어(textarea)의 너비와 높이를 지정하기 위해서 rows와 cols 속성이 사용됩니다.
기본값을 주고싶은경우
<textarea rows="5" cols="30" name="contents">이곳에 적어주십시오.</textarea> 이런식으로 주면 됩니다.
<td><input type="file" id="file" name="file" required /></td>
첨부파일의 경우에는 input type를 file로 받아주세요.
이곳에서 id와 name부분이 있는데요,
name은 page안에서 중복되어 사용이 가능하며 action에 해당하는 페이지로 전달하는 파라미터로 사용됩니다.
id는 page안에서의 중복 사용이 불가능하며 주로 javascript에서 다룰려고 지정하는 것 입니다.
따라서 잘모르겠다면, 저처럼 두개다 써주세요 ^^
retuired 이것도 중요합니다.
저것을 써줌으로써, file이 첨부되어야만 전송이 될수 있도록 해줍니다.
없애면, 첨부파일없이도 등록이가능해지겠죠!
^^
결과입니다. 좀...못생겼네요 ㅠㅠ