Uncategorized

PHP PDO IMAGE UPLOAD CODE

if(isset($_POST['submit'])){




     $allow = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "pdf", "PDF", "mp4", "MP4");
  //1st File
  if($_FILES['photo1']['name'] == "") {
    //echo "No Image"
  } else {

    $photo1=basename($_FILES['photo1']['name']);
    $extension = pathinfo($photo1, PATHINFO_EXTENSION);
    if(in_array($extension,$allow)){
      $target_path = "assets/images/documents/";
      $photo1 = md5(rand() * time()).'.'.$extension;
      $target_path = $target_path . $photo1;
      move_uploaded_file($_FILES['photo1']['tmp_name'], $target_path);
      $sql = ($photo1!='')?" inv_upload='$photo1' ". ',':'';
    }
  
  }
// insert code start 
  $insert_bookings = "INSERT `$table_name` SET 
  $sql
  column_1   = '$data1',
  column_2   = '$data2', ";   
  
  
$sql_insert = $dbconn->prepare($insert_bookings);
$sql_insert->execute();
$myid = $dbconn->lastInsertId();
  
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page&id=$myid");
}

Leave a Reply

Your email address will not be published. Required fields are marked *