{"id":32588,"date":"2016-02-11T14:19:02","date_gmt":"2016-02-11T08:49:02","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=32588"},"modified":"2016-03-03T17:26:35","modified_gmt":"2016-03-03T11:56:35","slug":"stylish-input-type-file-upload-with-image-preview","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/stylish-input-type-file-upload-with-image-preview\/","title":{"rendered":"Stylish input type file upload with image Preview"},"content":{"rendered":"<p>Few days back I have tried to change the look of input type file but unable to change like background,border etc. Actually, it looks different in all browsers.<\/p>\n<p>Now I found a solution to do this.<\/p>\n<p><strong>Here is the HTML which have been used:-<\/strong><\/p>\n<p>[java]<br \/>\n&lt;div class=&quot;uploadOuter&quot;&gt;<br \/>\n            &lt;input type=&quot;text&quot; class=&quot;uploadText&quot;\/&gt;<br \/>\n            &lt;input type=&quot;file&quot; class=&quot;uploadFile&quot;\/&gt;<br \/>\n        &lt;\/div&gt;<br \/>\n\t\t&lt;div class=&quot;Preview&quot;&gt;<br \/>\n\t\t&lt;img src=&quot;&quot; alt=&quot;&quot;\/&gt;<br \/>\n\t\t&lt;span class=&quot;loader&quot;&gt;&lt;\/span&gt;<br \/>\n\t\t&lt;\/div&gt;<br \/>\n[\/java]<\/p>\n<p>At first I have taken an outer div with name \u201cuploadOuter\u201d, then inserted an input type: text field showing the path of files selected locally. Afterwards, I have placed input type file which placed over the input type:text. Also I had set the opacity:None. For IMG Preview purpose I have taken &#8216;Preview&#8217; div.<\/p>\n<p>By using jQuery I have showcased the path of the selected file into the input type text and image Preview.<\/p>\n<p><strong>Here is the CSS which have been used:-<\/strong><\/p>\n<p>[java]<br \/>\n*{box-sizing:border-box;}<br \/>\n            .uploadOuter {margin: 6px 0;min-height:30px;border:1px solid #ccc;position: relative;width: 310px;}<br \/>\n            .uploadFile {opacity: 0;position: absolute;right: 0;top: 0;z-index: 2;height:100%; width: 100%;}<br \/>\n            .uploadText{width:100%;height:100%;position:absolute;border:none;padding:0 0 0 10px;background: url(&#8216;imagePathOfBrowseButton&#8217;) no-repeat right center}<br \/>\n\t\t\t.Preview{width:200px;border:1px solid #ccc;position:relative;display:none}<br \/>\n\t\t\t.Preview img{width:100%;}<br \/>\n\t\t\t.loader{position:absolute;left:0;top:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.5) url(&#8216;imagePath&#8217;) no-repeat center center;z-index:99; }<br \/>\n[\/java]<\/p>\n<p><strong>Here is the jQuery which have been used:-<\/strong><\/p>\n<p>[java]<br \/>\n$(function(){<br \/>\n\t\t\t\t$(&#8216;.uploadFile&#8217;).change(function(e){<br \/>\n\t\t\t\t$(&#8216;.loader&#8217;).show();<br \/>\n\t\t\t\t$(&#8216;.Preview&#8217;).show();<br \/>\n\t\t\t\t\tvar filePath = URL.createObjectURL(e.target.files[0]);<br \/>\n\t\t\t\t\tvar fileName = e.target.files[0].name;<br \/>\n\t\t\t\t\t\/\/var fileName = $(this).val();<br \/>\n\t\t\t\t\t$(&#8216;.uploadText&#8217;).val(fileName);<br \/>\n\t\t\t\t\t$(&#8216;.Preview img&#8217;).attr(&#8216;src&#8217;,filePath);<br \/>\n\t\t\t\t\t$(&#8216;img&#8217;).load(function(){<br \/>\n\t\t\t\t\t$(&#8216;.loader&#8217;).hide();<br \/>\n\t\t\t\t\t})<br \/>\n\t\t\t\t});<br \/>\n\t\t\t});<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Few days back I have tried to change the look of input type file but unable to change like background,border etc. Actually, it looks different in all browsers. Now I found a solution to do this. Here is the HTML which have been used:- [java] &lt;div class=&quot;uploadOuter&quot;&gt; &lt;input type=&quot;text&quot; class=&quot;uploadText&quot;\/&gt; &lt;input type=&quot;file&quot; class=&quot;uploadFile&quot;\/&gt; &lt;\/div&gt; &lt;div [&hellip;]<\/p>\n","protected":false},"author":228,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32588"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/228"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=32588"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32588\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=32588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=32588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=32588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}