how to detect if a file is a valid jpeg file ?

  • Thread starter Thread starter THY
  • Start date Start date
T

THY

Hi,

After we let the user upload file to the server, how do we actually detect
if that is a valid jpeg file ?

thanks,
Tee
 
Almost all standart files (such as jpg, gif, doc, ... ) have a header.
Look up jpeg file format and most likely the first 3 bytes will be preset to
something like (JPG).


George.
 
Anyone know how to do it ?


George Ter-Saakov said:
Almost all standart files (such as jpg, gif, doc, ... ) have a header.
Look up jpeg file format and most likely the first 3 bytes will be preset to
something like (JPG).


George.
 
Do what?
I looked up the "jpeg header" in a google for you.
First 2 bytes have FFD8 in them.

So just read first 2 bytes and compare them to FFD8.

George.
 
Why not check before upload?

Something like this:

If inpUploadPic.PostedFile.ContentType ="image/pjpeg" Then
'check file type to make sure is jpeg
If inpUploadPic.PostedFile.ContentLength < 52000 Then '
check file size < 50k or whatever you want
inpUploadPic.PostedFile.SaveAs(strUploadPath & "ad" &
intAdId & ".jpg")

where inpIploadPic is the name of your html file upload control.




THY wrote in message ...
 
Back
Top