I have a file input that gets the text from a file uploaded by a file input. It works fine with plain text but when I try and upload a RTF document it comes up with a load of garbled text.
I was wondering if I could convert the RTF document to a plain text file before displaying it on the screen.
Here is my code.
<html>
<body>
<input type="file" id="fileinput" />
<pre id="texts"></pre>
<script type="text/javascript">
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
document.getElementById("texts").innerHTML = contents;
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
</script>
</body>
</html>
I don't mind about keeping images or styles, I just want to display the text.
Thanks in advance.