{"id":12899,"date":"2013-08-22T22:19:20","date_gmt":"2013-08-23T03:19:20","guid":{"rendered":"http:\/\/blog.kenperlin.com\/?p=12899"},"modified":"2013-08-22T22:19:20","modified_gmt":"2013-08-23T03:19:20","slug":"the-mysteries-of-the-internet","status":"publish","type":"post","link":"http:\/\/blog.kenperlin.com\/?p=12899","title":{"rendered":"The mysteries of the internet"},"content":{"rendered":"<p>Today I wanted to learn how to load the contents of a file from my own computer into a web browser.  I did a Web search, and discovered lots of forums, tutorials and discussion groups on the topic.<\/p>\n<p>A number of the on-line discussions seemed to devolve into a kind of religious war, with some participants asserting that such a thing was simply impossible, and others saying that accessing a file from disk was sort of morally wrong.  Apparently it goes against the spirit of the Web.<\/p>\n<p>One odd thing about such assertions is that they seem to have no relationship to reality.  After all, if you&#8217;ve ever uploaded to a web site a document you wrote or an image you took (which nearly everyone has done by now), then you have clearly read the contents of a file from your computer into a web browser.<\/p>\n<p>I did find some tutorial sites on the topic, but they were all very long, with gnarly code that ran on for pages.  It had seemed like such a simple question, and I was astonished to find the on-line answers to be anything but straightforward.<\/p>\n<p>Eventually I figured out what was going on, by assembling little bits and pieces from different places.  When I was all done, the whole thing took just one line of HTML plus four lines of Javascript.  For those of you who care, here they are:<\/p>\n<p><small><br \/>\n&nbsp; &nbsp; &nbsp; &lt;input id=&#8221;input&#8221; type=&#8221;file&#8221;&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &#8230;<br \/>\n&nbsp; &nbsp; &nbsp; var chooser = document.getElementById(&#8216;input&#8217;);<br \/>\n&nbsp; &nbsp; &nbsp; var reader = new FileReader();<br \/>\n&nbsp; &nbsp; &nbsp; chooser.addEventListener(&#8216;change&#8217;, function() {reader.readAsText(this.files[0]);});<br \/>\n&nbsp; &nbsp; &nbsp; reader.onload = function() { fileText = this.result; }<br \/>\n<\/small>&nbsp;<\/p>\n<p>So what are all those people out there going on about?  I&#8217;m starting to suspect there may be something very odd about Web programming culture.<\/p>\n<p>I&#8217;m just not quite sure yet what it is.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I wanted to learn how to load the contents of a file from my own computer into a web browser. I did a Web search, and discovered lots of forums, tutorials and discussion groups on the topic. A number of the on-line discussions seemed to devolve into a kind of religious war, with some &hellip; <a href=\"http:\/\/blog.kenperlin.com\/?p=12899\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The mysteries of the internet&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/posts\/12899"}],"collection":[{"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12899"}],"version-history":[{"count":49,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/posts\/12899\/revisions"}],"predecessor-version":[{"id":12948,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=\/wp\/v2\/posts\/12899\/revisions\/12948"}],"wp:attachment":[{"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12899"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.kenperlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}