zoukankan      html  css  js  c++  java
  • 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>");
                    
                }

                    
            }
  • 相关阅读:
    三线程连续打印ABC
    Mybatis知识点总结
    【刷题】LeetCode 292 Nim Game
    Java界面编程-建立一个可以画出图形的简单框架
    第11章 持有对象
    第10章 内部类
    构造器和多态(Chapter8.3)
    对象的创建过程(chapter5.7.3)
    静态数据的初始化(Chapter5.7.2)
    final关键字
  • 原文地址:https://www.cnblogs.com/xiaodi/p/120475.html
Copyright © 2011-2022 走看看