jquery_ajaxupload,ajaxupload上传图片
web前端-js教程
本次使用AJAXUPLOAD做为上传客户端无刷上传插件,其最新版本为3.9,官方地址:http://valums.com/ajax-upload/横版游戏源码,vscode与vs兼容吗,ubuntu官方原版,tomcat怎么导入web,抓取 软件 爬虫,php点击加载更多,如何提高seo 外推帖子,手机页面网站源码分享,cms主题模板下载地址lzw
在页面中引入 jquery.min.1.4.2.js 和 ajaxupload.jsflash as3源码,vscode关连md,ubuntu如何查看硬盘配置,tomcat配置log,sqlite 获取新数据,js翻书插件,前端框架赔偿标准,爬虫制作程序图片,php简单源码,晓小seo,廉洁档案网站源码,flash个人网页模板下载,国外手机购物网站模板下载,帝国cms列表页面没有权限访问,think仓库管理系统开源,小程序商城 后台数据库源码lzw
HTML 代码:
问道1.59登陆器源码,ubuntu 查看内存情况,tomcat如何增大内存,爬虫+摩拜,个人记账网站源码PHP,seo是什么职seo好做吗lzw
#txtFileName {width: 300px;}.btnsubmit{border-bottom: #cc4f00 1px solid; border-left: #ff9000 1px solid;border-top: #ff9000 1px solid; border-right: #cc4f00 1px solid;text-align: center; padding: 2px 10px; line-height: 16px; background: #e36b0f; height: 24px; color: #fff; font-size: 12px; cursor: pointer;}上传图片:js代 码:浏览
$(function () {var button = $('#btnUp'), interval;new AjaxUpload(button, {//action: 'upload-test.php',文件上传服务器端执行的地址action: '/handler/AjaxuploadHandler.ashx',name: 'myfile',onSubmit: function (file, ext) {if (!(ext && /^(jpg|jpeg|JPG|JPEG)$/.test(ext))) {alert('图片格式不正确,请选择 jpg 格式的文件!', '系统提示');return false;}// change button text, when user selects filebutton.text('上传中');// If you want to allow uploading only 1 file at time,// you can disable upload buttonthis.disable();// Uploding -> Uploading. -> Uploading...interval = window.setInterval(function () {var text = button.text();if (text.length < 10) {button.text(text + '|');} else {button.text('上传中');}}, 200);},onComplete: function (file, response) {//file 本地文件名称,response 服务器端传回的信息button.text('上传图片(只允许上传JPG格式的图片,大小不得大于150K)');window.clearInterval(interval);// enable upload buttonthis.enable();var k = response.replace("服务器端 ajaxuploadhandler.ashx 代码", "").replace("", "");if (k == '-1') {alert('您上传的文件太大啦!请不要超过150K');}else {alert("服务器端传回的串:"+k);alert("本地文件名称:"+file);$("#txtFileName").val(k);$("").appendTo($('#imglist')).attr("src", k);}}});});
public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";HttpPostedFile postedFile = context.Request.Files[0];string savePath = "/upload/images/";int filelength = postedFile.ContentLength;int fileSize = 163600; //150Kstring fileName = "-1"; //返回的上传后的文件名if (filelength <= fileSize){byte[] buffer = new byte[filelength];postedFile.InputStream.Read(buffer, 0, filelength);fileName = UploadImage(buffer, savePath, "jpg");}context.Response.Write(fileName);}public static string UploadImage(byte[] imgBuffer, string uploadpath, string ext){try{System.IO.MemoryStream m = new MemoryStream(imgBuffer);if (!Directory.Exists(HttpContext.Current.Server.MapPath(uploadpath)))Directory.CreateDirectory(HttpContext.Current.Server.MapPath(uploadpath));string imgname = CreateIDCode() + "." + ext;string _path = HttpContext.Current.Server.MapPath(uploadpath) + imgname;Image img = Image.FromStream(m);if (ext == "jpg")img.Save(_path, System.Drawing.Imaging.ImageFormat.Jpeg);elseimg.Save(_path, System.Drawing.Imaging.ImageFormat.Gif);m.Close();return uploadpath + imgname;}catch (Exception ex){return ex.Message;}}public static string CreateIDCode(){DateTime Time1 = DateTime.Now.ToUniversalTime();DateTime Time2 = Convert.ToDateTime("1970-01-01");TimeSpan span = Time1 - Time2; //span就是两个日期之间的差额 string t = span.TotalMilliseconds.ToString("0");return t;}在PHP网站开发中,文件上传功能时常用到,之前我已介绍过如何利用PHP实现文件上传功能。随着WEB技术的发展,用户体验成为衡量网站成功与否的关键,今天和大家分享如何在PHP中利用Jquery实现Ajax方式文件上传功能的例子,其中使用到了Jquery插件Ajaxupload,其可以实现单个文件和多文件上传功能。
AjaxUpload
Jquery插件AjaxUpload实现文件上传功能时无需创建form表单,即可实现Ajax方式的文件上传,当然根据需要也可以创建form表单。
准备工作
1、下载Jquery开发包和文件上传插件AjaxUpload。
2、创建uploadfile.html,并引入Jquery开发包和AjaxUpload插件
3、根据Jquery插件AjaxUpload的需要,创建一个触发Ajax文件上传功能的DIV