Я использую стиль файла начальной загрузки. Я установил на нем проверку Jquery, которая работает, но я не знаю, в чем проблема в моем коде. Я загружаю изображение в формате jpg, png, jpeg, gif, но проверка по-прежнему показывает ошибку после загрузки изображения.
Я имею в виду, что я не могу загрузить изображение, потому что я получаю сообщение об ошибке проверки, но я использую правильное изображение. Я загружаю изображение в формате jpg, но все еще показывает ошибку "File must be JPG, GIF or PNG"
. Не могли бы вы помочь мне в этом?
$(":file").filestyle({buttonBefore: true,buttonText: "Upload Image"});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(250)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
$(function() {
$("form[name='registration']").validate({
// Specify the validation rules
rules: {
fileToUpload: {
required: true,
accept: "png|jpe?g|gif"
}
},
// Specify the validation error messages
messages: {
fileToUpload: {
required: "Please upload image",
accept: "File must be JPG, GIF or PNG"
}
},
submitHandler: function(form) {
form.submit();
}
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-filestyle/1.2.1/bootstrap-filestyle.min.js"></script>
<form name="registration" method="post" action="process.php">
<input type='file' onchange="readURL(this);" class="filestyle input-field" data-buttonBefore="true" data-buttonText="Upload Image" name="fileToUpload" id="fileToUpload" />
<input type="submit" name="submit" value="submit">
</form>