SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: filtype check

  1. #1
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    filtype check

    Hi.
    I'm trying to check what type of file id beeing uploaded in my uplad form.
    This is the code I'm trying to use.
    PHP Code:
    //Check if image is jpg
    $type $_FILES['filetoupload']['type'];
    //echo "$type"; (outputs "image/jpeg"
    if (!$type == 'image/jpeg');
    {
       echo 
    "<span class=\"redtext\">Picture must be jpeg!</span>";
       exit();

    If I echo $type it outputs "image/jpeg". but still I can't seem to make it work...
    Anyone got som tips on how to make this work?

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't your fourth line be...

    PHP Code:
    if ($type != 'image/jpeg'); 
    edit: actually that probably doesn't make a difference, but it might be worth trying.
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility
    Shouldn't your fourth line be...

    PHP Code:
    if ($type != 'image/jpeg'); 
    edit: actually that probably doesn't make a difference, but it might be worth trying.
    Doesn't make a difference, but your way is MUCH more readable. Going if (!1==1) just looks weird.

    Have you tried echoing $type and seeing what it is? Perhaps your file upload field name is wrong?

  4. #4
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by someonewhois
    Have you tried echoing $type and seeing what it is? Perhaps your file upload field name is wrong?
    Yes, I have tried that, and it's: image/jpeg
    The file upload field name is correct to, it works in the rest of the code...
    I don't understand why, this shouldn't work, I'm going to try: if
    PHP Code:
    ($type != 'image/jpeg'); 

  5. #5
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It didn't make any difference.
    One question: does both (!1 == 1) and (1 != 1 ) invert the output from true to false?

  6. #6
    SitePoint Addict say's Avatar
    Join Date
    Sep 2003
    Location
    At work
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get rid of the semi colon:

    PHP Code:
    if (!$type == 'image/jpeg'); <--- 

  7. #7
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by say
    Get rid of the semi colon:

    PHP Code:
    if (!$type == 'image/jpeg'); <--- 
    that should be the problem indeed

    say had a good night rest, that's for sure
    The Path of excess leeds to the tower of wisdom (W. Blake)

  8. #8
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LMAO. Thanks alot say
    Sometimes the obvious is lost in it's own obviousness.


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
  •