上传图片

 

<div style="display: none">
        <asp:LinkButton ID="liBtnUplodLogo" runat="server" OnClick="liBtnUplodLogo_Click"></asp:LinkButton>
    </div>

 

<img id="ParkLogo" runat="server" οnerrοr='this.src="http://images.cnblogs.com/defava.jpg"' style="float: left;" />
                        <input id="fileUploadLogo" runat="server" name="fileUploadLogo" style="width: auto;
                            height: auto; display: none" type="file" οnchange="UploadTempLogo();" />
                        <asp:TextBox ID="txtFilePath" Width="172px" runat="server" Text=""></asp:TextBox>
                        <input type="button" value="浏览图片" style="width: 80px" οnclick="fn_clickFile();" />
                        <img id="tempImg" runat="server" src="" style="width: 100px; height: 50px;" />

      function fn_clickFile() {
            $("#fileUploadLogo").click();
            var filePath = $("#fileUploadLogo").val();
            $("#txtFilePath").val(filePath);
        }

        //上传临时文件
        function UploadTempLogo() {
            __doPostBack('liBtnUplodLogo', '');
        }

 

 

  private static string fileUploadLogoValue = string.Empty;
        private static string FileName = string.Empty;
        private static string UploadStr = string.Empty;
        private static string oldFilepath = string.Empty;

 

    /// <summary>
    /// 上传临时文件
    /// </summary>
    /// <param name="parkId"></param>
    /// <returns></returns>
    private bool UploadTempLogo()
    {
        fileUploadLogoValue = fileUploadLogo.Value;
        var baseFilePath = ConfigurationManager.AppSettings["tempParkLogo"];
        if (string.IsNullOrEmpty(fileUploadLogo.Value))
        {
            Alert("请选择上传图片");
            return false;
        }
        if (!string.IsNullOrEmpty(fileUploadLogo.Value))
        {
            string type = fileUploadLogo.Value.Substring(fileUploadLogo.Value.LastIndexOf(".") + 1).ToLower();
            if (!(type == "jpg" || type == "bmp" || type == "jpeg" || type == "png" || type == "gif"))
            {
                Alert("只能上传后缀名为jpg,bmp,jpeg,gif,png的图片");
                return false;
            }
        }
        var logoUpload = fileUploadLogo.PostedFile;
        FileName = logoUpload.FileName;
        var logoFileName = string.Empty;
        var logoPath = string.Empty;
        var basePath = baseFilePath;
        if (!Directory.Exists(basePath))
        {
            basePath = basePath + "/";
            FileHelper.FolderCreate(basePath);
        }
        else
        {
            basePath = basePath + "/";
        }
        if (!string.IsNullOrEmpty(logoUpload.FileName))
        {
            logoFileName = DateTime.Now.Ticks + "bus" + System.IO.Path.GetExtension(logoUpload.FileName);
            logoPath = basePath + logoFileName;

            logoUpload.SaveAs(logoPath);
            oldFilepath = logoPath;
            tempImg.Src = "http://a.inyyx.com/ParkImage/ParkTempLogo/" + logoFileName;
            txtFilePath.Text = fileUploadLogoValue;
        }

        UploadStr = Path.GetExtension(logoUpload.ToString());
        var loutName = DateTime.Now.Ticks + "logo" + Path.GetExtension(logoUpload.ToString());

        string ppth = baseFilePath + "/";
        if (!Directory.Exists(ppth))
        {
            Directory.CreateDirectory(ppth);
        }

        var largePath = "l.jpg";
        var middlePath = "m.jpg";
        var smallPath = "s.jpg";



        var LPath = ppth + largePath;
        var MPath = ppth + middlePath;
        var SPath = ppth + smallPath;

        ImageHelper.Resize(basePath + logoFileName, LPath, 150, 150, true, false);     //大图路径
        ImageHelper.Resize(basePath + logoFileName, MPath, 80, 80, true, false);      //中图路径
        ImageHelper.Resize(basePath + logoFileName, SPath, 30, 30, true, false);      //小图路径

        return true;
    }

    public void UploadParkLogo(Guid merchantId)
    {
        var baseFilePath = ConfigurationManager.AppSettings["MerchantLogo"];
        if (string.IsNullOrEmpty(fileUploadLogoValue))
        {
            Alert("请选择上传图片");
            return;
        }
        if (!string.IsNullOrEmpty(fileUploadLogoValue))
        {
            string type = fileUploadLogoValue.Substring(fileUploadLogoValue.LastIndexOf(".") + 1).ToLower();
            if (!(type == "jpg" || type == "bmp" || type == "jpeg" || type == "png" || type == "gif"))
            {
                Alert("只能上传后缀名为jpg,bmp,jpeg,gif,png的图片");
                return;
            }
        }

        var logoFileName = string.Empty;
        var logoPath = string.Empty;
        var basePath = baseFilePath;
        if (!Directory.Exists(basePath + merchantId))
        {
            basePath = basePath + merchantId + "/";
            FileHelper.FolderCreate(basePath);
        }
        else
        {
            basePath = basePath + merchantId + "/";
        }

        if (!string.IsNullOrEmpty(fileUploadLogoValue))
        {
            logoFileName = "merchantLogo.jpg";
            logoPath = basePath + logoFileName;
            BaiKeTool.FileHelper.FileCoppy(oldFilepath, logoPath);
        }

        var loutName = DateTime.Now.Ticks + "merchant" + Path.GetExtension(UploadStr);

        string ppl = baseFilePath + merchantId + "/";
        if (!Directory.Exists(ppl))
        {
            Directory.CreateDirectory(ppl);
        }

        var LPath = ppl + "l.jpg";
        var MPath = ppl + "m.jpg";
        var SPath = ppl + "s.jpg";

        ImageHelper.Resize(basePath + logoFileName, LPath, 150, 150, true, false);     //大图路径
        ImageHelper.Resize(basePath + logoFileName, MPath, 80, 80, true, false);      //中图路径
        ImageHelper.Resize(basePath + logoFileName, SPath, 50, 50, true, false);      //中图路径
    }

    protected void liBtnUplodLogo_Click(object sender, EventArgs e)
    {
        UploadTempLogo();
    }

转载于:https://www.cnblogs.com/Mancy/p/3303309.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值