• UBB


    1.UBB的保存。直接保存,通过javascript,以UBB格式直接保存在数据库里。关键问题要过滤掉不安全代码。
    例如:
            public string Filtrate(string content)
            
    {
                
    if(content == null)
                    
    return "";
                content 
    = content.Replace("<"," ");
                content 
    = content.Replace(">"," ");
                
    return(content);    
            }

    2.UBB的显示。
    using System;
    using System.Text;
    using System.Text.RegularExpressions;

    namespace UBB
    {
        
    /// <summary> 
        
    /// 功能:UBB代码
        
    /// 作者:小迪
        
    /// 日期:2005-3-20
        
    /// </summary>

        public class UBB
        
    {
            
    构造函数

            
    UBBToHTML
        }

    }


    补:
                    处理[upload]标记,处理上传图片 

    其实是上传任何文件,如果只要传图片,则可以在程序中加以控制(如,控制后缀名)

    改进:

        处理[upload]标记,处理上传图片 

    相关文件:


            
    private void ibtnUpLoad_Click(object sender, System.Web.UI.ImageClickEventArgs e)
            
    {
                
    if(upLoadFile.PostedFile.ContentLength > 524288)
                
    {
                    
    this.Response.Write("<script>alert('图片请控制在500K以内!谢谢')</script>");
                    
    return;

                }


                HttpPostedFile hpPFile 
    = upLoadFile.PostedFile;    
                
    string localFile = hpPFile.FileName;

                
    //设置路径
                string strFolderName=Server.MapPath("UpLoadPic");
                
    //取得文件类型(后缀名)
                char[] separator2 = {'.'};        //separator的值为"\"
                string[] temp2  = localFile.Split(separator2);
                
    string strFileType  = temp2[temp2.Length-1];
                
                
    //取得文件名(不含路径)
                char separator3 = '.';
                
    string strTemp  = localFile.Substring(0,localFile.LastIndexOf(separator3)-1);
                
    char[] separator = {'\\'};        //separator的值为"\"
                string[] temp  = strTemp.Split(separator);
                
    string strFileName  = temp[temp.Length-1];            

                System.IO.FileStream fs 
    = new FileStream(localFile,FileMode.Open);
                Bitmap bit 
    = new Bitmap(fs);
                
    int picWidth = bit.Width;
                
    int picHeight = bit.Height;
                fs.Close();

                
    string FileName = strFolderName + "\\upload_" + strFileName + "_" + picWidth + "_" + picHeight + "." + strFileType;
                    
                
    if(strFileType.ToLower() == "gif" || strFileType.ToLower() == "jpg")
                
    {
                    
    try
                    
    {
                        hpPFile.SaveAs(FileName);            
                        content.Value 
    += "[upload_" + strFileName + "_" + picWidth + "_" + picHeight + "." + strFileType + "]";                    
                        
    this.Response.Write("<script>alert('上传成功!')</script>");
                    }

                    
    catch
                    
    {
                        
    this.Response.Write("<script>alert('上传失败!请重试!')</script>");
                    }

                    
                }

                
    else
                
    {
                    
    this.Response.Write("<script>alert('请选择有效的图片文件,目前只支持.gif和.jpg格式的图片!')</script>");
                    
                }

                    
            }
  • 相关阅读:
    Webpack实现按需打包Lodash的几种方法详解
    一文带你了解babel-preset-env
    Vue-给对象新增属性(使用Vue.$set())
    vue v-slot
    Vue2.4+新增属性.sync、$attrs、$listeners
    彻底搞定Javascript事件循环
    Spring Boot 添加JSP支持【转】
    防火墙设置
    黑黑客客
    tomcat启动时设定环境变量
  • 原文地址:https://www.cnblogs.com/xiaodi/p/120475.html
Copyright © 2020-2023  润新知