SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Filesystem test if jpeg/gif/png

    How is it possible to check the file type ?

    Down to the specific of testing for jpg, jpeg, gif, png. I can test if its a file but what type i need to test on

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    If it for an upload use $_FILES['userfile']['type']
    if it on the server, use the explode() function eg
    PHP Code:
    $filename 'wallop.jpg';
    $filename_ext explode("."$filename);
    echo 
    $filename_ext[1]; 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats superb. The later is what I needed.

    Can I ask. Now to do the IF statement.

    Instead of doing this
    Code:
    if($filename_ext[1] == this || $filename_ext[1] == this || $filename_ext[1] == this || $filename_ext[1] == this ||({
          then do this
    }
    can you do one if check but compare it against a full array or somthing so the if dont become huge.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use in_array() or regular expression for this.

    As to your question in general, you should realize you're actually checking only the file extension, not the file type, i.e. contents. This may lead to security problems. To check uploaded images correctly consider using getimagesize()


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
  •