Skip to content
How to load a file from a `<input type="file">` and put it into the element `rixxyplayerCode`?
Profile icon
RixTheTyrunt

I tried a StackOverflow link that shows how to read uploaded files and put it into a element, but seems like the code didn't work ( Some of that code are NOT FROM THE ANSWER ) . How to do it?

You are viewing a single comment. View All
Profile icon
MattDESTROYER

@RixTheTyrunt If you've just copied and pasted the code block I posted that won't work, this is probably what you should do:

<div id="rixxyplayerCode" spellcheck="false" style="display: none;"></div> <script type="text/javascript"> function openFile(event, useDataUrl = false) { let reader = new FileReader(); reader.onload = function () { document.getElementById("rixxyplayerCode").textContent = reader.result; }; if (useDataUrl) { reader.readAsDataURL(event.target.files[0]); } else { reader.readAsText(event.target.files[0]); } } </script> <input type="file" onchange="openFile(event);" />