How would I add an "else" statement here.

Discussion in 'PHP' started by JAKEBRAKE, Nov 3, 2009.

  1. #1
    I am wanting to add a default preview image here that would be super ceded if a user uploads their own preview image. Can anyone tell me how to modify this code so I could achieve this.

    //upload photo preview
    $_FILES["preview2"]['name']=result_file($_FILES["preview2"]['name']);
    $nf=explode(".",$_FILES["preview2"]['name']);

    if((strtolower($nf[count($nf)-1])=="jpg" or strtolower($nf[count($nf)-1])=="jpeg" or strtolower($nf[count($nf)-1])=="gif" or strtolower($nf[count($nf)-1])=="png") and !eregi("text",$_FILES["preview2"]['type']))
    {
    if($_FILES["preview2"]['size']>0 and $_FILES["preview2"]['size']<2048*1024)
    {
    $vp=site_root."/content/".$folder."/thumb.".$nf[count($nf)-1];
    move_uploaded_file($_FILES["preview2"]['tmp_name'],$_SERVER["DOCUMENT_ROOT"].$vp);




    if(strtolower($nf[count($nf)-1])=="jpg" or strtolower($nf[count($nf)-1])=="jpeg")
    {

    $size = getimagesize ($_SERVER["DOCUMENT_ROOT"].$vp);

    $wd1=$site_thumb_width;
    $wd2=$site_thumb_width2;
    if(isset($size[1]))
    {
    if($size[0]<$size[1]){$wd1=$size[0]*$site_thumb_height/$size[1];$wd2=$size[0]*$site_thumb_height2/$size[1];}
    }

    easyResize($_SERVER["DOCUMENT_ROOT"].$vp,$_SERVER["DOCUMENT_ROOT"].$vp,100,$wd1);

    }




    $swait=true;


    $sql="update audio set photo='".result($vp)."' where id_parent=".$id;
    $db->execute($sql);


    }
    }






    }
    }
     
    JAKEBRAKE, Nov 3, 2009 IP
  2. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    None of this code has to do with what you want...you need to add that on the insert not update.

    BTW here is some revised code.

    
    //upload photo preview
    $_FILES["preview2"]['name']=result_file($_FILES["preview2"]['name']);
    $nf=explode(".",strtolower($_FILES["preview2"]['name']));
    $allowedExts=array('jpg','jpeg','png','gif');
    if(in_array($nf[count($nf)-1],$allowedExts) && !eregi("text",$_FILES["preview2"]['type']))
    {
        if(intval($_FILES["preview2"]['size']) and intval($_FILES["preview2"]['size'])<2048*1024)
        {
            $vp=site_root."/content/".$folder."/thumb.".$nf[count($nf)-1];
            move_uploaded_file($_FILES["preview2"]['tmp_name'],$_SERVER["DOCUMENT_ROOT"].$vp);
    
            if(strtolower($nf[count($nf)-1])=="jpg" or strtolower($nf[count($nf)-1])=="jpeg")
            {
            
                $size = getimagesize ($_SERVER["DOCUMENT_ROOT"].$vp);
                
                $wd1=$site_thumb_width;
                $wd2=$site_thumb_width2;
                if(isset($size[1]))
                {
                     if($size[0]<$size[1])
                     {
                        $wd1=$size[0]*$site_thumb_height/$size[1];
                        $wd2=$size[0]*$site_thumb_height2/$size[1];
                     }
                }
                
                easyResize($_SERVER["DOCUMENT_ROOT"].$vp,$_SERVER["DOCUMENT_ROOT"].$vp,100,$wd1);
       		}
      
            $swait=true;
            
            
            $sql="update audio set photo='".result($vp)."' where id_parent=".$id;
            $db->execute($sql);
        
        
        }
    }
    
    PHP:
     
    NatalicWolf, Nov 3, 2009 IP
  3. JAKEBRAKE

    JAKEBRAKE Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, I'm very new.I guess I gave it away... Well thanks for the help. Updated how? New and Improved? I am afraid to add, very quirky script.
     
    JAKEBRAKE, Nov 3, 2009 IP
  4. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, i'd be willing to help with anything, just feel free to ask. I added a few sanity checks and changed how things are checked. Example is the extensions, they are now an array instead. Just compare the code and you'll find the differences.
     
    NatalicWolf, Nov 3, 2009 IP
  5. JAKEBRAKE

    JAKEBRAKE Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I thank you kindly.

    I received a parse error

    Parse error: syntax error, unexpected $end in ....../upload_audio.php on line 270
     
    JAKEBRAKE, Nov 3, 2009 IP
  6. JAKEBRAKE

    JAKEBRAKE Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    would complete page help?
     
    JAKEBRAKE, Nov 3, 2009 IP
  7. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes. It probably would. Try doing indenting where possible.
     
    NatalicWolf, Nov 3, 2009 IP