本文实例为大家分享了基于jQuery Ajax实现上传文件的关键代码,供大家参考,具体内容如下
JS代码:
ASP.NET MVC后台代码:
//首先判断路径是否存在,不存在则创建路径string path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["UploadsFiles"], folder + "/" + DateTime.Now.ToString("yyyyMMdd") + "/");string physicalPath = server.MapPath(path);if (!Directory.Exists(physicalPath)){ Directory.CreateDirectory(physicalPath);}HttpPostedFileBase file = request.Files[0];string newFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);string savePath = Path.Combine(physicalPath, newFileName);file.SaveAs(savePath);fileName = file.FileName;string url = Path.Combine(path, newFileName);return url;更多精彩内容,请点击《jQuery上传操作汇总》,进行深入学习和研究。
以上就是本文的全部内容,希望对大家的学习有所帮助。