darryljf

add.php

Mar 18th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. $Category = new Category($Conn);
  2.  
  3. $categories = $Category->getAllCategories();
  4.  
  5. // pass this data to categories.tpl template file
  6. $smarty->assign('categories',$categories);
  7.  
  8. if($_POST){
  9.   if(!$_POST['recipe_name']){
  10.     $error = "Recipe name not set";
  11.   }else if(!$_POST['recipe_instructions']){
  12.     $error = "Recipe instructions not set";
  13.   }else if(!isset($_FILES['recipe_name'])){
  14.     $error = "Please upload a recipe image";
  15.   }
  16.  
  17.   if($error){
  18.     $smarty->assign('error', $error);
  19.   }else{
  20.     $random = substr(str_shuffle(MD5(microtime())), 0,10);
  21.     $new_filename = $random .$_FILES['recipe_image']['name'];
  22.     if(move_uploaded_file($_FILES["recipe_image"]["tmp_name"],__DIR__.'/../user_images/'.$new_filename)){
  23.  
  24.       $attempt = new Recipe;
  25.       $attempt->addRecipe($_POST);
  26.  
  27.       if($attempt){
  28.         $smarty->assign('success',"Your recipe has been added");
  29.       }else{
  30.         $smarty->assign('error',"An error occured.");
  31.       }
  32.     }
  33.   }
  34. }
Add Comment
Please, Sign In to add comment