Secure Image Upload Script

<!-- Input -->
<input type="file" name="image" accept="image/x-png,image/gif,image/jpeg" id="file" onchange="return fileValidation()" required>
<!-- Image preview -->
<div  id="imagePreview"></div>

<!-- Script -->
<script type="text/javascript">
function fileValidation(){
  var fileInput = document.getElementById('file');
  var filePath = fileInput.value;
  var allowedExtensions = /(\.jpg|\.jpeg|\.png|\.gif)$/i;
  //Image extensions
  if(!allowedExtensions.exec(filePath)){
      alert('Please upload file having extensions .jpeg/.jpg/.png/.gif...
WebBeer - Beer & Code | Product Hunt Embed