Check filesize before upload

爱⌒轻易说出口 提交于 2019-11-28 14:13:16

You can read local files in JavaScript using file reader in HTML5:
http://www.html5rocks.com/en/tutorials/file/dndfiles/

function handleFileSelect(evt) {
  var files = evt.target.files; // FileList object

  // files is a FileList of File objects. List some properties.
  var output = [];
  for (var i = 0, f; f = files[i]; i++) {
    console.log(f.size);        /*<--Here is your size of the file! :D*/
  }
}

document.getElementById('files').addEventListener('change', handleFileSelect, false);

If you use php you can set php option - 'upload_max_filesize'. See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize May be it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!