DEV Community

Cover image for File upload -> Filesize
Frank Wisniewski
Frank Wisniewski

Posted on • Updated on

File upload -> Filesize

It happens again and again that inexperienced users want to upload unnecessarily large files to the server.

With this little onchange oneLiner you can check that before uploading.

Use data-mfs=.... (....=fileSize)

<!DOCTYPE html>
<html lang=de>
<head>
  <meta charset=UTF-8>
  <title>Document</title>
    <h1>check max filesize</h1>
  <form>
    <input type=file  
           name=filename 
           data-mfs=100000 onchange="this.setCustomValidity(this.files[0].size>this.dataset.mfs?'to big!!':'')" 
           required>
    <input type=submit>
  </form>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)