Hello, i have this table events:

id_evento, evento_texto, evento_banner, evento_image, evento_cartaz, evento_idioma

Now i can upload the image to evento_banner and evento_image, because they're the same only changes the size (the code is "inside" the <form>):

<?php
     if(isset($_POST['Submit'])){
      //Declara um Array para armazenar a mensagem de erro
      $error = array();  

//se o nome for entregue
      if (empty($_POST['text'])){
       $error[] = "text miss";
      }else{
       $text=$_POST['text'];
      }

if (empty($_POST['cidade'])){
       $error[] = "cidade";
      }else{
       $cidade=$_POST['cidade'];
      }

      if (empty($_FILES["file"]["name"])){
       $error[] = "Choose an image for the band";
      }else{
       $image=$_FILES["file"]["name"];
      }


      //send to Database if there's no error '
      if (empty($error)) // If everything's OK...
      {
       $idioma=$_POST['idioma'];

       error_reporting(0);
       $change="";
       $abc="";
       define ("MAX_SIZE","2048");

       function getExtension($str){
        $i = strrpos($str,".");
        if (!$i) { return ""; }
        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);
        return $ext;
       }

       $errors=0;

       if($_SERVER["REQUEST_METHOD"] == "POST")
       {
        $uploadedfile = $_FILES['file']['tmp_name'];
        if ($image)
        {
         $filename = stripslashes($_FILES['file']['name']);
         $extension = getExtension($filename);
         $extension = strtolower($extension);
         if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")){
          $change='<div class="notification n-error">Unknown Image extension </div> ';
          $errors=1;
         }else{
          $size=filesize($_FILES['file']['tmp_name']);
          if ($size > MAX_SIZE*1024){
           $change='<div class="notification n-error">You have exceeded the size limit!</div> ';
           $errors=1;
          }

          if($extension=="jpg" || $extension=="jpeg" ){
           $uploadedfile = $_FILES['file']['tmp_name'];
           $src = imagecreatefromjpeg($uploadedfile);
          }else if($extension=="png"){
           $uploadedfile = $_FILES['file']['tmp_name'];
           $src = imagecreatefrompng($uploadedfile);
          }else{
           $src = imagecreatefromgif($uploadedfile);
          }
          echo $scr;
          list($width,$height)=getimagesize($uploadedfile);
          $newwidth=900;
          $newheight=($height/$width)*$newwidth;
          $tmp=imagecreatetruecolor($newwidth,$newheight);
          $newwidth1=300;
          $newheight1=($height/$width)*$newwidth1;
          $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
          imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
          imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
          $filename = "../../images/bands/". $_FILES['file']['name'];

          $file=explode(".".$extension, $_FILES['file']['name']);

          $filename1 = "../../images/bands/".$file[0]."_small".".".$extension;

          imagejpeg($tmp,$filename,100);
          imagejpeg($tmp1,$filename1,100);
          imagedestroy($src);
          imagedestroy($tmp);
          imagedestroy($tmp1);
         }
        }
       }
       //If no errors registred, print the success message
       if(!$errors)
       {
        $image=explode('../', $filename);
         $image1=explode('../', $filename1);


         $insert=("INSERT INTO eventos(evento_texto, evento_cidade, evento_banner, evento_image, evento_idioma)
             VALUES ('".$text."', '".$cidade."', '", '".$image[2]."', '".$image1[2]."', '".$idioma."')");
         if(mysql_query($insert)){
          header('Location: eventos.php');
         }
         else{
          echo '<div class="notification n-error">'.mysql_error().'.</div>';
         }
        }
        else{
         echo '<div class="notification n-error">The band already exists!</div>';
        }
      }else{
       //If the "error" array contains error msg , display them
       echo '<div class="notification n-error" <ul>';
       foreach ($error as $key => $values)
       {
        echo '<li>'.$values.'</li>';
       }

       echo '</ul></div>';
      }
     }
     ?>

My goal is to add a different image to evento_cartaz.

Can someone help me?

Thank You

Add a separate file upload to your form, and process it apart from the other one.

Extra 1: you may wanna consider changing some coding habits, like giving your variables names that represent better what they do, so $tmp is $tmp_img and $tmp1is $tmp_event, same for $filename1 and $newwidth1.

Extra 2: explicitly telling your file input in the form that calls this php which file types you allow for upload may save you some code lines in the file type validation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.