I am playing around in my code and trying to implement a system to where a user can choose a file then the file they select can replace the placeholder image that is already provided in the code.I am getting an error in Jquery that the file cannot be found and the uploaded is broken and has 'fakepath in it' like this : file:///C:/fakepath/IMG_0136.JPG which looks wrong. Code is below. Any help is appreciated!
$('.button3').click(function() {
var fileName = $('.fileName').val().toString().toLowerCase();
var fileSplit = fileName.split(".");
var file;
if (fileSplit[1] == "jpg" || fileSplit[1] == "png") {
file = $('.fileName').val();
$('.navbar2 ul li.logo img').attr('src',file);
}
<input type="file" class="fileName" name="pic" accept="image/*">
<a><i class="fa fa-times" aria-hidden="true"></i></a>
<div class="button3"></div>
<div class="button3">
<h2>Submit</h2>
<div class="loading-signal"></div>
<div class="successful3"><i class="fa fa-check" aria-hidden="true"></i>
</div>
</div>