FCK集成SWF,.NET版

网上有一个集成SWF的实例,但是拿下来后发现实例有一小BUG,就是上传的图片都是一个命名的话,点确定后会出现所有的图片都是同一张,但是实际上所有的图片也都上传到服务器了,原因是多图片上传的时候直接记录下了本地图片的命名,而非上传至服务器后的命名。比如本地有文件两个,分别为“新建文件夹1”和“新建文件夹2”而且同时里面都存在一张名为“未命名”的图片,但图片的内容是不一样的。这样在上传的时候就会出现这个BUG了。

这样的话只要修改掉SWF上传时所记录的那个图片名为上传后的图片名即可解决。

看了一下Upload_Pic.aspx这个文件,最简单的方法是用Session记录下上传后的文件名,其中Page_Load直接修改为以下

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            // Get the data
            HttpPostedFile postedFile = Request.Files["Filedata"];


            const string DEFAULT_USER_FILES_PATH = "/upload/";


            string userFilesPath = "";
            if (userFilesPath == null || userFilesPath.Length == 0)
                userFilesPath = DEFAULT_USER_FILES_PATH;

            if (!userFilesPath.EndsWith("/"))
                userFilesPath += "/";

            string ex = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')).ToLower();
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(100, 999).ToString() + ex;           
            Session["_filename"] += fileName + ",";
          

            postedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~/" + userFilesPath + "/" + fileName));
            Response.StatusCode = 200;

 

        }
        catch
        {
            // If any kind of error occurs return a 500 Internal Server error
            Response.StatusCode = 500;
            Response.Write("An error occured");
            Response.End();
        }
        finally
        {

            Response.End();
        }
    }

找到handlers.js找到以下两个函数修改为如下

function uploadSuccess(file, serverData) {
    try {
  var progress = new FileProgress(file, this.customSettings.progressTarget);
  progress.setComplete();
  progress.setStatus("Complete.");
  progress.toggleCancel(false);
  //文件名存到隐藏域 edit:jiangchao0304@gmai.com
  $.ajax({
      type: "POST",
      url: "/admin/Handler.ashx",
      data: "getfile=getfile",
      success: function (data) {
          document.getElementById("hdFileName").value = data;
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
          alert(errorThrown);
      }
  });

 } catch (ex) {
  this.debug(ex);
 }
}

function uploadComplete(file) {
 try {
     /*  I want the next upload to continue automatically so I'll call startUpload here */    
  if (this.getStats().files_queued === 0) {
      document.getElementById(this.customSettings.cancelButtonId).disabled = true;
      $.ajax({
          type: "POST",
          url: "/admin/Handler.ashx",
          data: "clean=clean",
          success: function (data) {
             
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
              alert(errorThrown);
          }
      });
  } else {
   this.startUpload();
  }
 } catch (ex) {
  this.debug(ex);
 }
}

用的是Ajax来操作的

其中Handler.ashx的内容如下

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState

{
   
    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        if (context.Request["getfile"] != null)
        {
            context.Response.Write(context.Session["_filename"].ToString());
        }
        if (context.Request["clean"] != null)
        {
            context.Session["_filename"] = "";
            context.Response.Write(context.Session["_filename"].ToString());
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

 

以下是还没有做修改的Demo链接:

http://download.csdn.net/detail/jeanny292163/4329349

 

本人转行后的一些小心得,有更好的解决方案请不吝赐教。。。各位大神们勿笑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值