Get filename from input [type='file'] using jQuery

前端 未结 11 993
陌清茗
陌清茗 2020-12-23 20:15

This is the uploaded form.

11条回答
  •  时光说笑
    2020-12-23 20:29

    This was a very important issue for me in order for my site to be multilingual. So here is my conclusion tested in Firefox and Chrome.

    jQuery trigger comes in handy.

    So this hides the standard boring type=file labels. You can place any label you want and format anyway. I customized a script from http://demo.smarttutorials.net/ajax1/. The script allows multiple file uploads with thumbnail preview and uses PHP and MySQL.

    
        
    Select a file
    $('#select_file').click(function() { $('#images_up').trigger('click'); $('#images_up').change(function() { var filename = $('#images_up').val(); if (filename.substring(3,11) == 'fakepath') { filename = filename.substring(12); } // Remove c:\fake at beginning from localhost chrome $('#my_file').html(filename); }); });

提交回复
热议问题