You must Sign In to post a response.
  • Category: ASP.NET

    How to check whether it is really an image

    i have upload image to database. how to check file contents to ensure the field is really an image...for example someone can rename an .exe file and send the file as 'image' how can validate this kind of issues
  • #571654
    You can check it's type by using postefile.contenttype

  • #571655
    if (postedfile.contenttype != "Image")
    upload to database
    else
    give message

  • #571659
    The data base store the image in Binary format, so there is no option to check for the Image type there, but while converting it back to the image if there is some error that means the data is not Image compatible.
    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #571661
    thanks soujanya i find it works well..

    Anil this working fine...

    if FileUpload1.PostedFile.ContentType = "image/pjpeg" Then
    label1.Text="its a real image
    End If

    Regards
    N.Ravindran
    Your Hard work never fails

  • #571663
    you can check it using postedFile.contentType
    other wise another option is there get the extension of the uploaded file and check whether it matches your criteria or not like you want only gif and jpg format file then this way you can place validation


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.