javascript - Image preview not working properly -
i have code shows image before uploading not working shows image if there no height or width set if try fix height , width same dimensions doesn't works properly
<?php echo '<input type="file" id="changeme" name="file" multiple/> <div id="output"></div> </div> <div id="right"> <script> function fileload(e) { var files=e.target.files || e.datatransfer.files (var i=0, f; f=files[i]; i++) { parsefile(f) } } function parsefile(file) { var reader=new filereader(); reader.onload=function (e) { var output=document.getelementbyid("output"); output.innerhtml +="<img src=" + e.target.result + " />"; } reader.readasdataurl(file); } if(window.file && window.filelist && window.filereader) { var fileselect=document.getelementbyid("changeme"); fileselect.addeventlistener("change", fileload); } </script>'; ?> it works fine way when enter dimensions height="50" , width="50" in image tag image doesn't show tried using css image doesn't work. note:- have use inside php reasons
i think it's because don't wrap in quotes values <img> tag. try this:
output.innerhtml +="<img src=\'" + e.target.result + "\' style=\'width: 50px; height: 50px;\' />"; note escaped single quotes avoid problems in php echo
Comments
Post a Comment