如何进行图像的名称验证

如何进行图像的名称验证

本文介绍了如何进行图像的名称验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来进行图像名称验证,以便每次用户发送/发布名称已经存在的图像时都会发送消息。



问题是人们一遍又一遍地发布相同的图像,因为没有什么可以阻止他们这样做。现在我需要找到一种方法来阻止它,以便每次用户发送相同的图像时,消息框出现并说此图像已经存在,以便用户可能知道现在我需要更改并发布另一个。请帮忙!



这是我的代码:



I need a way of making an image name validation so that a message is sent every time a user sends/posts an image with a name that already exists.

The problem is people posts the same images all over and again because the is nothing that stops them from doing so. Now i need to find a way of putting a stop to that so that every time a user sends the same image a Message Box shows up and say "This image already exist" so that the user may know that now i need to change and post another one. Please help!

Here's my code:

public class ImageHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {

        {
            System.Data.SqlClient.SqlDataReader rdr = null;
            System.Data.SqlClient.SqlConnection conn = null;
            System.Data.SqlClient.SqlCommand selcmd = null;
            try
            {
                //string path =""
                conn = new System.Data.SqlClient.SqlConnection
              (System.Configuration.ConfigurationManager.ConnectionStrings
              ["LiveAdsConnectionString"].ConnectionString);
                selcmd = new System.Data.SqlClient.SqlCommand
             ("select Image from Adverts where AdvertsID=" +
              context.Request.QueryString["id"], conn);
                conn.Open();
                rdr = selcmd.ExecuteReader();
                while (rdr.Read())
                {
                    context.Response.ContentType = "image/jpg";
                    context.Response.ContentType = "image/png";
                    context.Response.WriteFile("/Images/" + rdr["Image"].ToString());
                }
                if (rdr != null)
                    rdr.Close();
            }
            finally
            {
                if (conn != null)
                    conn.Close();
            }

        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }

推荐答案


这篇关于如何进行图像的名称验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:55