Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
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
Archives
Today
Total
관리 메뉴

자기 혐오 개발자

file업로드시 이미지 미리 썸네일로 보여주기 본문

Java,JSP

file업로드시 이미지 미리 썸네일로 보여주기

올라치노 2018. 6. 15. 19:04

       javascript 단.


 function fileUpload(fis) {

            var str = fis.value;

            $('#span').text(fis.value.substring(str.lastIndexOf("\\")+1));

            // 이미지를 변경한다.

              var reader = new FileReader();

      reader.onload = function(e){

$('#loadImg').attr('src',e.target.result);

      }

reader.readAsDataURL(fis.files[0]);

}




html단


<th>이미지</th>

<td>

<img src="" id="loadImg" style="width: 50px;height:50px;"/>

<button type="button" id="file_btn">첨부파일</button><span id="span">등록된 첨부파일이 없습니다.</span>

<input type="file" id="file" class="form-control" name="file" style="display:none;" onchange="fileUpload(this);">

<span id="error_file" class="error_txt"></span>

</td>