zoukankan      html  css  js  c++  java
  • 上传文件验证 格式 与 大小

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script src="jquery-1.7.1.min.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function(){
       
      $("#form01").change( function(){
       
      var filepath=$("input[name='myFile']").val();
       
      var extStart=filepath.lastIndexOf(".");
       
      var ext=filepath.substring(extStart,filepath.length).toUpperCase();
       
      if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
       
      alert("图片限于bmp,png,gif,jpeg,jpg格式");
      return false;
      }else{$("#name01").text(ext)}
       
      var file_size = 0;
      if ( $.browser.msie) {
      var img=new Image();
      img.src=filepath;
      while(true){
      if(img.fileSize > 0){
      if(img.fileSize>3*1024*1024){
       
      alert("图片不大于100MB。");
      }else{
      var num03 = img.fileSize/1024;
      num04 = num03.toFixed(2)
      $(".size02").text(num04+"KB");
      }
      break;
      }
      }
      } else {
      file_size = this.files[0].size;
      console.log(file_size/1024/1024 + " MB");
       
      var size = file_size / 1024;
      if(size > 10240){
      alert("上传的文件大小不能超过10M!");
      }else{
      var num01 = file_size/1024;
      num02 = num01.toFixed(2)
      $("#size01").text(num02 + " KB");
      }
      }
      return true;
      });
       
      });
      </script>
      <title>无标题文档</title>
      </head>
       
      <body>
      <table width="500" cellspacing="0" cellpadding="0">
      <tr>
      <td width="72" id="name01">&nbsp;</td>
      <td width="242"><input type="file" name="myFile" id="form01" /></td>
      <td width="184" id="size01" class="size02">&nbsp;</td>
      </tr>
      </table>
       
      </body>
      </html>
       
  • 相关阅读:
    动态属性 的简单思考
    千发 邮件营销小工具 完全免费
    基于角色的代码权限
    VS2005对NHibernate映射文件的智能感知功能
    在ASP.NET中使用脚本代码保护功能
    ASP.NET 开发, PageBase, ModuleBase
    在自定义HttpHandler中使用Session
    C# 应用程序许可控制
    TCE条件表达式
    NHibernate 基本使用(一对一、组件、一对多)
  • 原文地址:https://www.cnblogs.com/yingjie13/p/4138589.html
Copyright © 2011-2022 走看看