서버에 업로드하기 전에 html 페이지에서 사진을 미리 볼 수있는 방법이 있습니까?
변경 사항이 있음을 보여주기 위해 업로드해야하는 이미지의 미리보기를 표시해야합니다. 이미지 소스를 변경해야 할 것입니다. 내가 사용할 수있는 기존 기술 / 방법이 있습니까?
최근에이 문제를 다음과 같이 해결했습니다.
changelistener를 fileinput에 바인딩했습니다.
<input type="file" name="photofile" id="photofile">
$('#photofile').bind("change", function(){
readUrl(this);
});
readURL 함수의 이미지를 다음과 같이 이전에 비어있는 img 요소로 설정합니다.
readUrl = function(input) {
//if File is there
if(input.files && input.files[0]) {
//create a Filereader
var reader = new FileReader();
//bind a function to the reader which will be executed when file is completely loaded
reader.onload = function(e) {
//Here you render your preview image
$("#bild-vorschau").attr("src", e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
여기 Working Fiddle 에서 볼 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다