码迷,mamicode.com
首页 > Web开发 > 详细

js实现文件上传

时间:2016-06-20 14:00:51      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

js
 function UpladFile() {



        var fileObj = document.getElementById("filetes").files[0]; // 获取文件对象

        var FileController = "/Home/upfile";                    // 接收上传文件的后台地址 



        // FormData 对象

        var form = new FormData();

        form.append("author", "hooyes");                        // 可以增加表单数据

        form.append("file", fileObj);                           // 文件对象



        // XMLHttpRequest 对象

        var xhr = new XMLHttpRequest();

        xhr.open("post", FileController, true);

        xhr.onload = function () {

            alert("上传完成!");

        };

        xhr.send(form);



    }
后台
var flist = Request.Files;



            for (int i = 0; i < flist.Count; i++)

            {

                string FilePath = "D:";

                var c = flist[i];

                FilePath = Path.Combine(FilePath, c.FileName);

                c.SaveAs(FilePath);

            }

  

js实现文件上传

标签:

原文地址:http://www.cnblogs.com/cainiaoyangchengji/p/5600221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!