zoukankan      html  css  js  c++  java
  • JQ中的FormData对象 ajax上传文件

    HTML代码:

    <form enctype="multipart/form-data" method="POST" name="searchform" id="searchform">

                 <table width="0%" border="0" cellspacing="0" cellpadding="0" class="bk_add_box">

                   <tr>

    <td width="140" align="right"><b>选择文件:</b></td>

    <td align="left">

    <input name="member_info" type="file" id="member_info" size="48" style="float:left;150px;">

    <span class="tips" >注:请上传*.XLS文件~!</span>

    </td>

    </tr>

                   <tr>

                    <td width="140" align="right"></td>

                     <td align="left">

                         <a href="javascript:;" class="enter_btn"  onclick="$('#searchform').submit();">导入会员信息</a>

                     </td>

                   </tr>

                 </table>

    </form>

    ########################################################################################################################################

    JQ代码:

    <script type="text/javascript">

    $(function(){

        $('#searchform').submit(function(){

            var data = new FormData($('#searchform')[0]);

            // return console.log(data);

            $.ajax({

                type: 'POST',

                url: '/member_manage/?act=import_member_info_ajax',

                data: data,

                dataType: 'JSON',

                cache: false,

                processData: false,

                contentType: false,

                success: function(json) {

                    if(json.error == 0) {

                        __alert(json.data, false, function() {

                         window.location.reload();

                        });

                    }else {

                        return _alert(json.data);

                    }

                }

            });  

            return false;   

        });

    });

    </script>

    ########################################################################################################################################

    获取上传文件类型名

                $filetype = strrchr($_FILES["input_name"]["name"], ".");         //截取点之后的字符串  包括点

                $filetype = substr($filetype, 1, strlen($filetype));                       //把 点去除

                $filetype = strtolower($filetype);//截取文件类型名                   //所有字符串都转换成小写

    ########################################################################################################################################

  • 相关阅读:
    数据科学工作者(Data Scientist) 的日常工作内容包括什么
    Python中的startswith和endswith函数使用实例
    Python中的startswith和endswith函数使用实例
    简单制作 OS X Yosemite 10.10 正式版U盘USB启动安装盘方法教程
    error splicing file: file too large解决方法
    Django authentication 使用方法
    什么是mixin
    Python: 什么是*args和**kwargs
    django migration使用指南
    python如何获取某模块的版本信息
  • 原文地址:https://www.cnblogs.com/xionghao/p/6768092.html
Copyright © 2011-2022 走看看