zoukankan      html  css  js  c++  java
  • 上传图片时获取所传图片大小

      在<head></head>之前写入以下Javascript代码:

     1        <script language=javascript>
     2        //上传4张图片,分别是4张图片的大小
     3        var FileSize = new Array(0000);
     4        //当前选择框的索引
     5        var FileIndex = 0;
     6        //选择文件后显示到Img中
     7        function ChangeSrc(hifilObj, Index)
     8        {
     9            document.all.imgBeforeUpload.src = hifilObj.value;
    10            FileIndex = Index;
    11        }

    12        //获得图片信息
    13        function GetSize()
    14        {
    15            FileSize[FileIndex] = document.all.imgBeforeUpload.fileSize;
    16        }

    17        //清零
    18        function SetSizeZero()
    19        {
    20            if(document.all.imgBeforeUpload.src == "")
    21                FileSize[FileIndex] = 0;
    22        }

    23        </script>
    24

      在<html></html>间定义一个Img:
    <img src="" id="imgBeforeUpload" onreadystatechange="GetSize()" onpropertychange="SetSizeZero()" style="DISPLAY:none">

      及4个文件选择控件:
    <INPUT class="text" type="file" id="hifil0" runat="server" onpropertychange="ChangeSrc(this, 0)">
    <INPUT class="text" type="file" id="hifil1" runat="server" onpropertychange="ChangeSrc(this, 1)">
    <INPUT class="text" type="file" id="hifil2" runat="server" onpropertychange="ChangeSrc(this, 2)">
    <INPUT class="text" type="file" id="hifil3" runat="server" onpropertychange="ChangeSrc(this, 3)">

      然后就可以在提交表单之前来判断FileSize的大小来控制大小了。
  • 相关阅读:
    Python open 读和写
    Sublime Text的使用
    解决MySQL Workbench导出乱码问题
    统计学(一)
    pymysql使用(二)
    使用pymysql(使用一)
    2个Excel表格核对技巧
    用Python读写Excel文件的方式比较
    从零上手Python关键代码
    php面试
  • 原文地址:https://www.cnblogs.com/faib/p/661947.html
Copyright © 2011-2022 走看看