图片上传

====================html========================================

 <td class="label1" style="width: 15%">
                       测试图:
                 </td>
                 <td>
                    <input type ="file" value ="上传" name ="tempImage" id="tempImage"/>
                    <input type ="button" id="btnUpLoadImage"  value ="上传" class ="btn"  onclick ="UpLoadImage()"/>
                   
                    <div id="images">
                        <ul id="U14" class="gallery">
                            
                        </ul> 
                    </div>
                    
                </td>

====================javascript========================================

function UpLoadImage()

        {
            $('#UploadForm').attr("action", "/sation/handlers/UploadImage.ashx");
            $('#divBillboardImage').parent().appendTo($('#UploadForm'));
            $("#UploadForm").ajaxSubmit({
                url:  "/sation/handlers/UploadImage.ashx",
                type: "post",
                dataType: "json",
                success: function(data) 
                {
                   if (data.resault == "ok") {                
                         $("#U14").append("<li><div><img width='120px' url='"+data .SavePath+"' class='image1' height='120px'  src='" + data.ServerPath + "'/><br/><a  href='javascript:void(0)' οnclick='DelImage(this,1)' >删除</a></div></li>");
                    }
                    else if (data.resault == "error") {
                        alert(data.msg);
                    };
                },
                error:function ()
                {
                    alert ("异常");
                }
            });


        } 
        function DelImage(obj,index)
        {
            var li=obj .parentNode.parentNode;
            li .remove();
            var images="";
            $(".image"+index).each(function (){
                images +=$(this ).attr("url")+"|";
            })
            alert (images);
            alert ($(".image"+index).length);
             $("#<%=HiddenImages.ClientID %>").val(Images);
               $.ajax({
                            type: "get",
                            url: "/sation/handlers/ServicesItem/UpdateImage.ashx",
                            data:{"Images":Images,"id":<%=ServiceItemID%>},
                            success: function(msg) {
                                if (msg == "ok") {    
                                    alert("删除成功");                
//                                     window.location.href=location .href ;
                                } else {
                                    alert("删除成功");
                                }
                            },
                            error: function(msg) {
                                alert("请求异常");
                            }
                        });
           }

        }



====================一般处理程序========================================

context.Response.ContentType = "text/plain";
        HttpPostedFile File = context.Request.Files["tempImage"];
        if (File != null)
        {
            FileSettingEntity fileVaild = FileManger.GetFileSetting((int)ESourceType.fromStationImg);
            if (File.ContentLength > fileVaild.Length)
            {
                context.Response.Write("{\"resault\":\"error\",\"msg\":\"" + "上传的图片大小不能超过" + fileVaild.Length / 1024 + "kb!" + "\"}");
                return;
            }
            FileEntity fentity = null;
            try
            {
                fentity = Gasgoo.B2C.Common.FileUpload.ReceptionUploadFixedGIPImage(File, ESourceType.fromStationImg, 0, UserId, false);
            }
            catch
            {
                context.Response.Write("{\"resault\":\"error\",\"msg\":\"请上传.jpeg|.jpg|.gif格式文件!\"}");
                return;
            }
            string Path = FileFactory.GetFilePathByFileArray(fentity.SavePath, ESourceType.fromStationImg);
            string ImgFile = string.Empty;
            ImgFile = "{\"resault\":\"ok\",";
            ImgFile += "\"msg\":\"\",";
            ImgFile += "\"SavePath\":\"" + fentity.SavePath + "\",";
            ImgFile += "\"ServerPath\":\"" + Path + "\"";
            ImgFile += "}";
            context.Response.Write(ImgFile);
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值