DEV Community

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

Posted on • Edited on

3 2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay