JSFiddle - React, Tailwind, and code Playground

by Gustavo Juan

HTML

<input type="file" id="file">

JavaScript

var input = Ext.select("input[type=file]").elements[0]
console.log(input)
input.addEventListener('change', uploadFile, false);


function uploadFile(){
     var input = Ext.select("input[type=file]");
    var file = Ext.select("input[type=file]").elements[0].files[0];
    

    var ext = file.name.split(".").pop();
    var titulo = file.name.split(".");
    titulo  = titulo[0];
    var nombre = uniqid()+"."+ext;
    var tempID = (new Date().getTime()/1000).toString();
    console.log(ext);
    console.log(titulo)
    console.log(nombre);
    console.log(tempID);   
    console.log(file);
    
    
    var options = new FormData();
    options.append("file",file);

    var reader = new FileReader();
    reader.onload = function(e){
        console.log(e.target.result);
    }
    reader.readAsDataURL(file);
}





function uniqid (prefix, more_entropy) {

    if (typeof prefix === 'undefined') {

        prefix = "";
    }

    var retId;
    var formatSeed = function (seed, reqWidth) {

        seed = parseInt(seed, 10).toString(16);

        if (reqWidth < seed.length) {

            return seed.slice(seed.length - reqWidth);
        }
        if (reqWidth > seed.length) {

            return Array(1 + (reqWidth - seed.length)).join('0') + seed;
        }

        return seed;
    };


    if (!this.php_js) {

        this.php_js = {};
    }

    if (!this.php_js.uniqidSeed) {

        this.php_js.uniqidSeed = Math.floor(Math.random() * 0x75bcd15);
    }

    this.php_js.uniqidSeed++;

    retId = prefix;
    retId += formatSeed(parseInt(new Date().getTime() / 1000, 10), 8);
    retId += formatSeed(this.php_js.uniqidSeed, 5);

    if (more_entropy) {

        retId += (Math.random() * 10).toFixed(8).toString();
    }

    return retId;
}