Skip to content

Instantly share code, notes, and snippets.

@danimal141
Created February 23, 2013 06:33
Show Gist options
  • Save danimal141/5018720 to your computer and use it in GitHub Desktop.
Save danimal141/5018720 to your computer and use it in GitHub Desktop.
use file API sample
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ファイル読み込みサンプル</title>
</head>
<body>
<form>
<input id="upload" type="file"/>
</form>
<div id="img_area">
<p>ここに画像表示しますよー</p>
</div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$("#upload").on("change", function(event){
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(e){
$("#img_area").empty().append($("<img>").attr("src", e.target.result));
};
   reader.readAsDataURL(file);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment