Jump to content

local file


valentinaCom
 Share

Recommended Posts

hi :)

 

I'm trying to upload a file from local disk to my project:

 

js:

function showMyImage(fileInput) {
    var files = fileInput.files;
    for (var i = 0; i < files.length; i++) {
        var file = files;
        var imageType = /image.*/;
        if (!file.type.match(imageType)) {
            continue;
        }
        var img= document.getElementById("thumbnil");
        img.file = file;
        var reader = new FileReader();
        reader.onload = (function(aImg) {
            return function(e) {
                aImg.src = e.target.result;
            };
        })(img);
        reader.readAsDataURL(file);
        console.log(reader)
    }
}
 
html:
<input type="file" accept="image/*"  onchange="showMyImage(this)" />
            <br/>
            <img id="thumbnil" style=""  src="" alt="image"/>
 
It's work. however I am trying to add the file (image) as a phaser image in the game. There is a way to do it?
 
thank you!
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...