728x90

MIME 타입 (MIME type, Multipurpose Internet Mail Extensions type) 의 약자로

인터넷에서 전송되는 파일의 형식을 식별하기 위한 식별자이다.

 

파일 업로드시 파일 확장자로 체크 하기도 하고 

MIME 타입으로 파일 확장자를 체크 해서 

입력 받아야할 파일 타입을 한번 더 걸러 준다. 

 

아래는 파일 확장자에 대한 MIME 타입과 

javascript 에서 체크 하는 로직을 예제로 보여 주고 있다.

 

pdf 파일

'application/pdf'

 

excel 파일

.xls 파일

'application/vnd.ms-excel'

.xlsx 파일

'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

 

hwp 한글 파일

'application/x-hwp'

doc 파일

'application/msword'

 

docx 파일

'application/vnd.openxmlformats-officedocument.wordprocessingml.document'

word파일

'application/msword'

이미지파일

image/jpeg : JPEG 이미지
image/png : PNG 이미지
image/gif : GIF 이미지
image/webp : WebP 이미지
image/bmp : BMP 이미지
image/svg+xml : SVG 이미지
image/tiff : TIFF 이미지

 

 

const fileTypes = ['application/pdf', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];

 

 

스크립트 예제>

script ex>

if (fileTypes.includes(file.type)) {
  // 업로드된 파일이 허용된 MIME 타입에 해당하는 경우 
} else {
  // 업로드된 파일이 허용되지 않은 MIME 타입에 해당하는 경우 
}

 

728x90
728x90

<!-- HTML 테이블 -->
<table id="myTable">
  <thead>
    <tr>
      <th>이름</th>
      <th>나이</th>
      <th>이메일</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>홍길동</td>
      <td>25</td>
      <td>hong@example.com</td>
    </tr>
    <tr>
      <td>김철수</td>
      <td>30</td>
      <td>kim@example.com</td>
    </tr>
  </tbody>
</table>

<!-- JavaScript 코드 -->
<script>
  // 테이블에서 행 추가
  function addRow() {
    var table = document.getElementById("myTable").getElementsByTagName('tbody')[0];
    var newRow = table.insertRow(table.length);
    var cells = [];
    for (var i = 0; i < 3; i++) {
      cells.push(newRow.insertCell(i));
      cells[i].innerHTML = "새 데이터";
    }
  }

  // 테이블에서 행 삭제
  function deleteRow() {
    var table = document.getElementById("myTable").getElementsByTagName('tbody')[0];
    var lastRow = table.rows.length - 1;
    table.deleteRow(lastRow);
  }
</script>

<!-- 추가/삭제 버튼 -->
<button onclick="addRow()">행 추가</button>
<button onclick="deleteRow()">행 삭제</button>

728x90

+ Recent posts