关于swfupload上传头像返回图像地址
来源:互联网 发布:淘宝新店访客怎么提升 编辑:程序博客网 时间:2024/05/16 10:28
<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title></title> <link href="css/css.css" rel="stylesheet" type="text/css" /><%-- <link href="css/StyleSheet1.css" rel="stylesheet" type="text/css" />--%> <script src="js/jquery.js" type="text/javascript"></script> <script src="swfupload/swfupload.js" type="text/javascript"></script> <script src="js/swfupload.queue.js" type="text/javascript"></script> <script src="js/fileprogress.js" type="text/javascript"></script> <script src="js/filegroupprogress.js" type="text/javascript"></script> <script src="js/handlers.js" type="text/javascript"></script> <script src="js/ajaxfileupload.js" type="text/javascript"></script> <style type="text/css"> #File1 { width: 143px; } </style> <script type="text/javascript"> var swfu; window.onload = function () { var settings = { flash_url: "swfupload/swfupload.swf", upload_url: "upload.ashx", file_size_limit: "100 MB", //上传文件体积上限,单位MB file_types: "*.jpg;*.bmp;*.ico;*.gif;*.png", //允许上传的文件类型 file_types_description: "Web Image Files", //文件类型描述 file_upload_limit: 10, //限定用户一次性最多上传多少个文件 file_queue_limit: 0, //上传队列数量限制,该项通常不需设置,会根据file_upload_limit自动赋值 custom_settings: { progressTarget: "divprogresscontainer", progressGroupTarget: "divprogressGroup", //progress object// container_css: "progressobj",// icoNormal_css: "IcoNormal",// icoWaiting_css: "IcoWaiting",// icoUpload_css: "IcoUpload",// fname_css: "fle ftt",// state_div_css: "statebarSmallDiv",// state_bar_css: "statebar",// percent_css: "ftt",// href_delete_css: "ftt",// //sum object// /*// 页面中不应出现以"cnt_"开头声明的元素// */// s_cnt_progress: "cnt_progress",// s_cnt_span_text: "fle",// s_cnt_progress_statebar: "cnt_progress_statebar",// s_cnt_progress_percent: "cnt_progress_percent",// s_cnt_progress_uploaded: "cnt_progress_uploaded",// s_cnt_progress_size: "cnt_progress_size" }, post_params : { "ASPSESSID" : "<%=session_id %>" }, debug: false, //是否显示调试信息 // Button settings //button_image_url: "images/upload.gif", button_width: "65", button_height: "29", button_placeholder_id: "spanButtonPlaceHolder", //这里就是上传按钮要应用到的容器的ID button_text: '<p><span class="theFont">上传文件</span></p>', button_text_style: ".theFont { font-size: 12;color:#0068B7; }", button_text_left_padding: 12, button_text_top_padding: 3, // The event handler functions are defined in handlers.js file_queued_handler: fileQueued,//fileQueued, file_queue_error_handler: fileQueueError, upload_start_handler: uploadStart, upload_progress_handler: uploadProgress, upload_error_handler: uploadError, upload_success_handler: Result,//uploadSuccess upload_complete_handler: uploadComplete, file_dialog_complete_handler: fileDialogComplete }; swfu = new SWFUpload(settings); }; function Result(file,serverData) { var data=serverData.split(':'); if(data[0]=="ok") { $("#img_head").attr("src", data[1]); }// $("#divprogresscontainer").css("display", "none");// $("#divprogressGroup").css("display", "none"); } </script></head><body> <form id="frmMain" action="upload.ashx" runat="server" enctype="multipart/form-data"> <p><asp:Image ID="img_head" runat="server" Width="100" Height="100" /></p> <%--<p><input id="File1" type="file" name="File1" /></p>--%> <span id="spanButtonPlaceHolder">上传文件</span> <%--<p style="cursor:pointer" onclick="upload()">上传</p>--%> <div id="divprogresscontainer" style="display:none"></div> <div id="divprogressGroup" style="display:none"></div><%-- </form>--%> </form></body></html>处理文件代码
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.IO;using System.Web.SessionState;using DAL;using System.Data;namespace StoreManage.admin{ /// <summary> /// upload 的摘要说明 /// </summary> public class upload : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { try { context.Response.ContentType = "text/plain"; HttpPostedFile file; string id = context.Request["ASPSESSID"]; for (int i = 0; i < context.Request.Files.Count; ++i) { file = context.Request.Files[i]; if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue; string path = "admin\\head_imgs\\"; Random ran = new Random(); string strName = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(10, 100) + Path.GetExtension(file.FileName); string mapPath = context.Server.MapPath("~"); string savePath = mapPath + "\\" + path + strName; file.SaveAs(savePath); //string id = context.Session["ID"].ToString(); if (id!="") { string sql = "update Admin_Users set Admin_Headimg='head_imgs/" + strName + "' where id="+id; int res = SqlHelper.ExecuteNonQuery(sql, CommandType.Text); } context.Response.Write("ok:head_imgs/" + strName); //context.Response.Write("head_imgs/" + strName ); //context.Response.End(); } } catch (Exception ex) { context.Response.StatusCode = 500; context.Response.Write(ex.Message); context.Response.End(); } finally { context.Response.End(); } } public bool IsReusable { get { return false; } } }}
记得引用这些js
0 0
- 关于swfupload上传头像返回图像地址
- SWFupload上传插件案例及头像的截取
- swfUpload文件上传教程 附带下载地址
- SWFUpload上传
- SWFUpload上传
- 头像截图上传两种方式(SWFUpload、一个简单易用的flash插件)
- SWFUpload logoFlash上传组件 SWFUpload
- 关于富头像上传的使用方法
- 关于上传头像到服务器的问题
- Android 关于头像裁剪上传的实现
- 图像(头像)选择,截取,压缩,上传的分享
- 图片批量上传 swfupload
- SWFUpload 批量上传文件
- EXT swfUpload 上传按钮
- SWFUpload上传文件
- swfupload--php上传说明
- 使用SWFUpload上传文件
- swfupload--php上传说明
- DEV gridlookup 赋值问题(重要)
- elf 格式快速掌握
- nginx安装第三方模块的方法
- ORACLE_CDC
- MySQL多表查询 一使用SELECT子句进行多表查询
- 关于swfupload上传头像返回图像地址
- MYSQL的事务处理主要有两种方法。
- Oracle 11g安装笔记
- Java的内存泄漏
- mysql总结笔记
- 用JS获得QQ号码的昵称,头像,生日
- 队列输入输出
- [学习笔记]JavaScript进阶
- Java学习整理系列之Java枚举类型的原理