How to get the value of the input type 'file'

Home Forums Porto Admin – Responsive HTML5 Template How to get the value of the input type 'file'

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10028943
    mjejun
    Participant

    Hello,

    I am currently working with datatables, using Editable Table. And I would like to make the row as required to be filled by the users.

    I have one question, for the column attachment, how do I get the value of the input type ‘file’ from the datatables? I need the value (the path of the files) to push to the database, but I can’t seem to figure out how to read it from the datatables.

    Please help.

    Thank you.


    #10028962
    Support2
    Keymaster

    Hello,

    You have two ways:

    1) Wrap the table inside a <form>, so when you click in a “Send” button you can get the file by GET or POST.

    2) Get the value by JS:
    (js/custom.js):

    $('.my-file-input').on('change', function(e){
        var filepath = $(this).val();
        
        // filepath
        console.log(filepath);
    
        if ( e.target.files[0] ) {
            // create reader
            var reader = new FileReader();
            reader.readAsText(e.target.files[0]);
            reader.onload = function(e) {
                
                // file content
                console.log(e.target.result);
            };
        }
    
    });

    HTML:

    <input class="my-file-input" type="file" name="attachment" />

    Hope it helps.

    Kind Regards,

    Rodrigo.


Viewing 2 posts - 1 through 2 (of 2 total)

This topic is marked as "RESOLVED" and can not rceive new replies.