Results 1 to 11 of 11

Thread: Confirm Image

  1. #1

    Thread Starter
    Lively Member THCfog's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    86

    Confirm Image

    I have a uploading script and i need to make sure that it isnt a exe (or anythign other than an image) being uploaded. For example, virus.exe.jpg. I need someting that would filter things like that out.

    <INPUT maxLength=128 name=image type=file ACCEPT="image/jpeg, image/jpg"> ..is what IS allowed.

    Is there any way to confirm that the file being uploaded is either a valid image, or dosent contain an extra.exe.jpf in the filename?


    Thanks ahead of time...

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If you open it up and read the first bytes. You can check if it has JFIF in the start...can't remember what bytes it is...but look up the JPEG structure...and if you can't find it, post again..and I will have a look...

    BTW is it more the JPG files that are allowed??? Gif ? BMP???

  3. #3

    Thread Starter
    Lively Member THCfog's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    86
    just .jpg's....


    thanks for the tip, ill do some searching.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    So then look up the JPG structure...

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    This is a VB example...

    VB Code:
    1. Public Type ThePicInfo
    2.     Type As String
    3.     Width As Long
    4.     Height As Long
    5. End Type
    6.  
    7. Private Function CheckPicSpecs(TheFile) As ThePicInfo
    8.     Dim TheContent, TheImageInfo As ThePicInfo, TheVar, TheFreeFile
    9.     TheFreeFile = FreeFile
    10.     Open TheFile For Binary As TheFreeFile
    11.     TheContent = Input(10, TheFreeFile)
    12.     Close TheFreeFile
    13.     If Mid(TheContent, 7, 4) = "JFIF" Then
    14.        TheImageInfo.Type = "JPG"
    15.        Open TheFile For Binary As TheFreeFile
    16.        TheContent = Input(167, TheFreeFile)
    17.        Close TheFreeFile
    18.        TheImageInfo.Height = Asc(Mid(TheContent, 165, 1)) + 256 * Asc(Mid(TheContent, 164, 1))
    19.        TheImageInfo.Width = Asc(Mid(TheContent, 167, 1)) + 256 * Asc(Mid(TheContent, 166, 1))
    20.     End If
    21.     If Mid(TheContent, 1, 3) = "GIF" Then
    22.        TheImageInfo.Type = "GIF"
    23.        TheImageInfo.Width = Asc(Mid(TheContent, 7, 1)) + 256 * Asc(Mid(TheContent, 8, 1))
    24.        TheImageInfo.Height = Asc(Mid(TheContent, 9, 1)) + 256 * Asc(Mid(TheContent, 10, 1))
    25.     End If
    26.     CheckPicSpecs = TheImageInfo
    27. End Function

    It looks like it is in the four bytes 7-10.

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    but vb is a lot different than php, you can't expect to enter that in php and have it work.

    so all you can do is check that it is not empty and that it is a jpg though the mime_type it sends. not sure if there is anything else you can do.

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Can't you read one byte at a time in PHP??? With a fixed string or something?

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    well I suppose you could, but why, it is the web there is no need to. once you check for an image then what else can you do? I mean so somebody uploads a file.exe.jpg, big deal, it is still an image and can be ran on the web can it? if you call it does it try to open a image? it is not like your OS where it can be run as vbs or something, and besides usually the OS hides the last extension so actually the file is like so file.exe.jpg.vbs so there is a big difference on the web.

    prove me wrong!!! if you can't then I stand by wha tI just said. I never heard of this problem. al you can check for and all you would need to check for is the extension and php doesn't hid the .vbs from you

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    phpman has a very good point, but if you want something anyways, why not just check the given filename? Search for an occurance of ".exe" and if you find it, reject it.

    It's as simple as that.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yeah so good he can't reply back

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    yeah so good he can't reply back
    Us Michigan folk aren't too bright.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width