对js插件uploadify的一些操作

前台JS代码

技术分享
<script>
$(function(){
 //行程图片上传
        $(".info-r  input[type=‘file‘]").uploadify({
            formData: {
//这里可以传一些其它参数到后台去。
                folder: ‘\\Upload\\TravelProduct\\King‘  //图片保存的路径,如果没有前面//,图片就会保存到后台处理的一个路径下面去,如有保存路径为D:\web\Upload\TravelProduct\King/图片名称;如没有路径为D:/web/ExtemdClass/Upload/TravelProduct/king/图片名称
            },
            swf: ‘/Theme/NewBlueVacation/images/uploadify.swf‘,
            uploader: ‘/ExtendClass/UploadFiles.ashx‘,
            width: 50,
            height: 20,
            buttonText: ‘  ‘,//上传按钮文字
            buttonImage: "/Theme/NewBlueVacation/images/btn.gif",//上传按钮路径
            fileTypeExts: ‘*.jpg;*.png;*.gif;*.bmp‘,
            onUploadSuccess: function (file, data, response) {
                var parentdiv = $(this.wrapper).parent().parent().parent();
                var picList = parentdiv.find(‘.pic-list‘);
                if (data == "0") {
                    $.messager.alert("提示", "上传失败!", ‘error‘);
                }
                else {
                    $.messager.alert("提示", "上传成功!", ‘info‘);
                    picList.append(‘<img src="‘ + data + ‘"/>‘);
                    var scenery = parentdiv.children("input[name=‘Scenery‘]");
                    scenery.val(scenery.val() + ‘|‘ + data);
                }
            }
        });
});
前台JS代码

后台图片处理代码

技术分享
using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Web
{
    /// <summary>
    /// UploadFiles 的摘要说明
    /// </summary>
    public class UploadFiles : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpPostedFile file = context.Request.Files["Filedata"];
            string Dir = "Upload";
            string uploadPath = "\\" + Dir + "\\TravelProduct\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
            
            var path=context.Request.QueryString["path"];
            if(path!=null && path.ToString()!="" )
                uploadPath = "\\" + Dir + "\\"+path+"\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";

            if (!string.IsNullOrEmpty(context.Request["folder"]))
            {
                uploadPath = HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\"; //从页面传过来的路径
            }
            string returnPath = uploadPath.Replace("\\", "/");
            if (!string.IsNullOrEmpty(context.Request["folder"]))
            {
                returnPath = context.Request["folder"].Replace("\\", "/")+"/";
            }
            try
            {
                uploadPath = HttpContext.Current.Server.MapPath(uploadPath);
            }
            catch (Exception e)
            { }
            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string fileType = Tool.MakeRandomNumber(8, 1) + Tool.GetPicType(file.FileName);
                file.SaveAs(uploadPath + fileType);
                //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                context.Response.Write(returnPath + fileType);
            }
            else
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
后台图片处理代码

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。