You can verify the file input using javascript.
Here is an example:
function checkFile(yourForm){
var fileVal = yourForm.elements['fileField'].value;
//RegEx for valid file name and extensions.
var pathExpression = "[?:[a-zA-Z0-9-_\.]+(?:.png|.jpeg|.gif)";
if(fileVal != ""){
if(!fileVal.toString().match(pathExpression) && confirm("The file is not a valid image. Do you want to continue?")){
yourForm.submit();
} else {
return;
}
} else {
if(confirm("Do you want to continue without adding image?")) {
yourForm.submit();
} else {
return;
}
}
}
In your html
<form name="yourForm" method="post" enctype="multipart/form-data"">
<input type="file" name="fileField" />
<input type="button" value="submit" onClick="checkFile(this.form)" />
</form>
Note pathExperssion can be customized. Another thing is checking the extension is not too reliable as anyone can inject a file name as extension. Click here for other info.