SHARE
TWEET

Untitled

a guest May 25th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   require_once('db.php');
  3.   $upload_dir = 'uploads/';
  4.  
  5.   if (isset($_POST['Submit'])) {
  6.     $title = $_POST['title'];
  7.     $text = $_POST['text'];
  8.     $content = $_POST['content'];
  9.  
  10.     $imgName = $_FILES['image']['name'];
  11.         $imgTmp = $_FILES['image']['tmp_name'];
  12.         $imgSize = $_FILES['image']['size'];
  13.  
  14.     if(empty($title)){
  15.             $errorMsg = 'Please add a title';
  16.         }elseif(empty($text)){
  17.             $errorMsg = 'Please input a text';
  18.         }elseif(empty($content)){
  19.             $errorMsg = 'Please input a content to display';
  20.         }else{
  21.  
  22.             $imgExt = strtolower(pathinfo($imgName, PATHINFO_EXTENSION));
  23.  
  24.             $allowExt  = array('jpeg', 'jpg', 'png', 'gif');
  25.  
  26.             $userPic = time().'_'.rand(1000,9999).'.'.$imgExt;
  27.  
  28.             if(in_array($imgExt, $allowExt)){
  29.  
  30.                 if($imgSize < 5000000){
  31.                     move_uploaded_file($imgTmp ,$upload_dir.$userPic);
  32.                 }else{
  33.                     $errorMsg = 'Image too large';
  34.                 }
  35.             }else{
  36.                 $errorMsg = 'Please select a valid image';
  37.             }
  38.         }
  39.  
  40.  
  41.         if(!isset($errorMsg)){
  42.             $sql = "insert into benefit_keys(title, text, content, image)
  43.                     values('".$title."', '".$text."', '".$content."', '".$userPic."')";
  44.             $result = mysqli_query($conn, $sql);
  45.             if($result){
  46.                 $successMsg = 'New record added successfully';
  47.                 header('Location: admin.php');
  48.             }else{
  49.                 $errorMsg = 'Error '.mysqli_error($conn);
  50.             }
  51.         }
  52.   }
  53. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top