I have a form that has two text fields and a file upload field.
The validation is handled completely from PHP and I'm using a little bit of Ajax to retrieve the error messages the PHP script produces via an array (err[]).
My problem is, I can't seem to get the file upload validation to work correctly. (when uploading a file, it will always say "Wrong file format only .png , .gif, .jpg, .jpeg are accepted")
The Ajax is below:
function checkform() {
$.post('upload.php', $("form#uploadForm").serialize(), function (data) {
$("div#error").html(data).slideDown("fast");
var destination = $('div#uploadContainer').offset().top - 15;
$("html:not(:animated),body:not(:animated)").animate({
scrollTop: destination
}, 200);
});
return false;
}
The following validation seems to ALWAYS be triggered:
$extension = strrchr($_FILES['uploadFile']['name'], '.');
if (!in_array($extension, $extensions)) {
$err[]='Wrong file format only .png , .gif, .jpg, .jpeg are accepted';
}
...
...