SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Location
    Home
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a way to simplify this condition?

    I am making an image upload script, and was thinking there was a way to turn this into an array. Is that possible, or was I wrong?

    PHP Code:
    if ($filetype != "image/gif" || $filetype != "image/jpg" || $filetype != "image/png" || $filetype != "image/jpeg") { 

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Not tested but something like@
    PHP Code:
    $img_filetypes = array(
              
    "image/gif"
            
    "image/jpg"
            
    "image/png"
            
    "image/jpeg"
        
    );
        
    if(!
    in_array($filetype$img_filetypes)) {
        
        
    //
        

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,037
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Yup you sure could do that

    PHP Code:
    $types=array("image/gif""image/jpg""image/png""image/jpeg");
    if (
    in_array($type$types)) { 
       
    // do something fun
    } else {
       
    // thou shalt not upload non-image files!



    Edit:


    spikeZ beat me to it
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Addict
    Join Date
    Oct 2005
    Location
    Home
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome. I'm fairly new to arrays, and wasn't unsure if this would work in it.

    Simplified my code a little bit, thanks!

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    wo0ot!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Addict
    Join Date
    Oct 2005
    Location
    Home
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, in your opinion, how big of a file should I allow to be uploaded?

    I'm thinking somewhere around 250-500kb because my server will have unlimited storage and bandwidth. My site is based around people uploading and sharing images. Unless there is a way I can have my code resize them a little smaller automatically?

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,037
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Yes on most servers you can [make images smaller], using the GD library.
    Take a look here: PHP: GD - Manual
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sam Rusch View Post
    By the way, in your opinion, how big of a file should I allow to be uploaded?

    I'm thinking somewhere around 250-500kb because my server will have unlimited storage and bandwidth. My site is based around people uploading and sharing images. Unless there is a way I can have my code resize them a little smaller automatically?
    Normally restrictions are defined in php settings files of file upload and post (2mb and 8mb)
    You should not forget about users internet connection as well as you site may be used in remote africa as well...
    sometimes people try to upload 1mb, 3000x2000 photo directly from digital camera memory so make sure that you check the max dimension as well...
    and when you upload think of least internet connection your user might have ,not your internet connection.
    If you try uploading 1mb files through 64kbps internet i wonder it will get uploaded at one go(or will need atleast animated progress bar to provide some clue to user)

    thanks


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
  •