This repository has been archived by the owner on Oct 9, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<title>File API (simple)</title> | ||
<article> | ||
<p id="status">File API & FileReader API not supported</p> | ||
<p><input type=file></p> | ||
<p>Select an image from your machine to read the contents of the file without using a server</p> | ||
<div id="holder"></div> | ||
</article> | ||
<script> | ||
var upload = document.getElementsByTagName('input')[0], | ||
holder = document.getElementById('holder'), | ||
state = document.getElementById('status'); | ||
|
||
if (typeof window.FileReader === 'undefined') { | ||
state.className = 'fail'; | ||
} else { | ||
state.className = 'success'; | ||
state.innerHTML = 'File API & FileReader available'; | ||
} | ||
|
||
upload.onchange = function (e) { | ||
e.preventDefault(); | ||
|
||
var file = upload.files[0], | ||
reader = new FileReader(); | ||
reader.onload = function (event) { | ||
var img = new Image(); | ||
img.src = event.target.result; | ||
// note: no onload required since we've got the dataurl...I think! :) | ||
if (img.width > 560) { // holder width | ||
img.width = 560; | ||
} | ||
holder.innerHTML = ''; | ||
holder.appendChild(img); | ||
}; | ||
reader.readAsDataURL(file); | ||
|
||
return false; | ||
}; | ||
</script> |