关于swfupload上传头像返回图像地址

<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" οnclick="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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值