SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    when a jpg is not a jpg

    For my user transfer file routine, I only want them to be able to transfer pics or pdf.
    I test the extension (jpg, jpeg, gif, png, pdf
    Up till now this has worked fine.
    BUT someone transfered a aaa.jpg YET it was not a jpg but a php.

    Is there some way to test a file for a pic or pdf other than the extension ?

    TIA
    Pat

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,195
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    You could try getimagesize() which should fail on anything than an image file.

    The problem is you will still need to upload it to use the getimagesize and it would not work with a pdf?

    I know jpg files all start with certain characters but I do not know how you could check that: http://en.wikipedia.org/wiki/Magic_number_(programming)

    P.S. There is a Unix program to detect file types but I have no idea how you would use it: http://en.wikipedia.org/wiki/File_(command)

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all for pointing me in the right direction.
    I'll get down to work to try these out.

    Pat


Bookmarks

Posting Permissions

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