SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Idea Developer
    Join Date
    Sep 2000
    Location
    Bethlehem, PA
    Posts
    521
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to tell if file is an image?

    How to tell that say file.jpg is an image?
    Professional PHP programing / Hosting
    aim: downtoi3iz icq: 74637813

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use GetImageSize() on the file name, and if the result array is populated it is an image.

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup - getimagesize index [2] would return 0 if the file wasn't gif, jpeg, png or swf
    teckis - that's news to me.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I pretty sure that the array wouldn't even populated if the file was not an image or swf.

  5. #5
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, one other thing you could do:

    get the name/path of the file in a string, and then do

    PHP Code:
    $format substr$fileName, -3);
    if(
    $format == "jpg")
    {
        return 
    true;

    And just check the format of the file.

    There is probably an easier way to do this

    P.S. (I'm not 100% sure about the syntax i used on the substr() function, but i think its close)

    =]
    Ryan

  6. #6
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can also use this if your using php4+

    http://www.php.net/manual/en/functio...-imagetype.php
    the neigbours (free) WIFI makes it just a little more fun


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
  •