Advertisement
darryljf

add.php - latest

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