Guest User

Untitled

a guest
Mar 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. if (isset($_POST['update_sub_categories']))
  2. {
  3. $file = $_FILES['Subcategory_image']['tmp_name'];
  4.  
  5. this are the conditions for update images
  6. if (file_exists($file))
  7. {
  8. $errors = array();
  9. $maxsize = 2097152;
  10. $acceptable = array(
  11. 'image/jpeg',
  12. 'image/jpg',
  13. 'image/gif',
  14. 'image/png'
  15. );
  16. if (($_FILES['Subcategory_image']['size'] >= $maxsize) || ($_FILES["Subcategory_image"]["size"] == 0))
  17. {
  18. $errors[] = 'File too large. File must be less than 2 megabytes.';
  19.  
  20. // code...
  21.  
  22. }
  23.  
  24. if (!in_array($_FILES['Subcategory_image']['type'], $acceptable) && (!empty($_FILES["Subcategory_image"]["type"])))
  25. {
  26. $errors[] = 'Invalid files type. Only JPG, GIF and PNG types are accepted';
  27. }
  28. }
  29.  
  30. if (count($errors) === 0)
  31. {
  32. move_uploaded_file($_FILES['Subcategory_image']['tmp_name'], 'images/categories/' . $_FILES['Subcategory_image']['name']);
  33. $Subcategory_image = $_FILES['Subcategory_image']['name'];
  34.  
  35. // code...
  36.  
  37. $m->set_data('Category_id', $Category_id);
  38. $m->set_data('Subcategory_description', $Subcategory_description);
  39. $m->set_data('Subcategory_name', $Subcategory_name);
  40. $m->set_data('Subcategory_image', $Subcategory_image);
  41. $a = array(
  42. 'Category_id' => $m->get_data('Category_id') ,
  43. 'Subcategory_description' => $m->get_data('Subcategory_description') ,
  44. 'Subcategory_name' => $m->get_data('Subcategory_name') ,
  45. 'Subcategory_image' => $m->get_data('Subcategory_image') ,
  46. );
  47. $q = $d->update("sub_categories", $a, "Subcategory_id='$Subcategory_id'");
  48. if ($q > 0)
  49. {
  50. header("location:Manage_subcategories.php");
  51. }
  52. else
  53. {
  54. echo "Error";
  55. }
  56. }
  57. else
  58. {
  59. header("location:Manage_subcategories.php?msg=invalidfile");
  60. }
  61. }
Add Comment
Please, Sign In to add comment