zoukankan      html  css  js  c++  java
  • [04]JS获取文件大小方法

    1. </pre><pre name="code" class="html"><input id="file" type="file">  
    2. <input id="Button1" type="button" value="button" onclick="check()">  
    3. <script>  
    4. window.check=function(){  
    5. var input = document.getElementById("file");  
    6. if(input.files){  
    7.                 //读取图片数据  
    8.   var f = input.files[0];  
    9.   var reader = new FileReader();  
    10.   reader.onload = function (e) {  
    11.       var data = e.target.result;  
    12.       //加载图片获取图片真实宽度和高度  
    13.       var image = new Image();  
    14.       image.onload=function(){  
    15.           var width = image.width;  
    16.           var height = image.height;  
    17.           alert(width+'======'+height+"====="+f.size);  
    18.       };  
    19.       image.src= data;  
    20.   };  
    21.       reader.readAsDataURL(f);  
    22.   }else{  
    23.       var image = new Image();   
    24.       image.onload =function(){  
    25.           var width = image.width;  
    26.           var height = image.height;  
    27.           var fileSize = image.fileSize;  
    28.           alert(width+'======'+height+"====="+fileSize);  
    29.       }  
    30.       image.src = input.value;  
    31.   }  
    32. }  
    33. </script>  

     转载 :http://blog.csdn.net/u014236259/article/details/52885591

  • 相关阅读:
    转:IOCP在网络应用中常见错误分析
    Ext.Button的禁用
    Excel连接字符串
    从表单为实体对象赋值
    根据指定类型创建数组
    Ext.GridPanel数据显示不正确
    vue 记事本
    杂谈(一)
    推荐《程序设计的 Top 10 做与不做》和《关于编程,鲜为人知的真相》
    (转)黄鸣博客:警惕29岁现象
  • 原文地址:https://www.cnblogs.com/yeziTesting/p/7691148.html
Copyright © 2011-2022 走看看