This is the uploaded form.
<form class="alert alert-info"> <div> <b id = "select_file" class="span3" style="font-weight: bold; cursor: pointer; ">Please select image</b> <input class="span3" type="file" name="image_file" id="image_file" style="display:none " /> <input disabled="true" type="button" value="Upload image" class="btn" /> </div> </form>
I use the following script to open a window with files. I want to show a file name in <b id = 'select_file'>
.
How can I do this?
$('#select_file').click(function(){ var _this = $(this); $('#image_file').show().focus().click().hide(); var filename = $('#image_file').val(); _this.html(filename); $('.btn').attr('disabled', false); });
var fullPath = $('#fileUpload1'). val();
length property in jQuery to check the file is selected or not. If element. files. length property returns 0 then the file is not selected otherwise file is selected.
Getting the file name is fairly easy. As matsko points out, you cannot get the full file path on the user's computer for security reasons.
var file = $('#image_file')[0].files[0] if (file){ console.log(file.name); }
You have to do this on the change event of the input type file
this way:
$('#select_file').click(function() { $('#image_file').show(); $('.btn').prop('disabled', false); $('#image_file').change(function() { var filename = $('#image_file').val(); $('#select_file').html(filename); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With