Javascript : Validate file upload


/ Published in: PHP
Save to your folder(s)

Image file upload, javascript


Copy this code and paste it in your HTML
  1. <script language="javascript">
  2. function Checkfiles()
  3. {
  4. var fup = document.getElementById('logo1');
  5. var fileName = fup.value;
  6. var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
  7. if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG")
  8. {
  9. return true;
  10. }
  11. else
  12. {
  13. alert("Upload JPG, JPEG, PNG, GIF images only");
  14. fup.focus();
  15. return false;
  16. }
  17. }
  18. </script>
  19.  
  20.  
  21. onchange="Checkfiles()"

URL: http://programming-tut.blogspot.in/2010/02/javascript-validate-file-upload.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.