Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. $directory = "../assets/product_image/";
  2. if (!dir($directory)) {
  3. die("Directory Not Found");
  4. }
  5.  
  6. $path = $_FILES['product_image']['name'];
  7. $ext = pathinfo($path, PATHINFO_EXTENSION);
  8.  
  9. $target_file = $directory . "product_" . uniqid() . "." . $ext;
  10.  
  11. $file_type = pathinfo($target_file, PATHINFO_EXTENSION);
  12. $file_size = $_FILES['product_image']['size'];
  13. $is_image = getimagesize($_FILES['product_image']['tmp_name']);
  14.  
  15. if ($is_image) {
  16. if (file_exists($target_file)) {
  17. echo 'This file Already exists';
  18. exit();
  19. } else {
  20. if ($file_size > 5242880) {
  21. echo 'File Size is Too Large.Please select a size within 5mb';
  22. exit();
  23. } else {
  24. if ($file_type != 'jpg' && $file_type != 'png') {
  25. die("File type is not vaild");
  26. } else {
  27.  
  28. if (move_uploaded_file($_FILES['product_image']['tmp_name'], $target_file)) {
  29. $sql = "INSERT INTO tbl_product(product_name,category_id,sub_category_id,manufacturer_id,product_price,stock_quantity,product_sku,product_short_description,product_long_description,product_image,publication_status) VALUES('$data[product_name]','$data[category_id]','$data[sub_category_id]','$data[manufacturer_id]','$data[product_price]','$data[stock_quantity]','$data[product_sku]','$data[product_short_description]','$data[product_long_description]','$target_file','$data[publication_status]')";
  30. if (mysqli_query($this->connect(), $sql)) {
  31. $message = "Product Informations Successfully Saved";
  32. return $message;
  33. } else {
  34. die("Query Problem") . mysqli_error($this->connect());
  35. }
  36. } else {
  37. die("Product Image Upload Error");
  38. }
  39. }
  40. }
  41. }
  42. } else {
  43. echo 'This is not a image';
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement