小迪的Blog
学习ing...(注明:该Blog中的任何信息都非原创,只是作为个人的阅读笔记)
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>");
                
            }

                
        }
posted on 2005-03-17 15:39  小迪  阅读(1274)  评论(1编辑  收藏  举报