Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $directory = "../assets/product_image/";
- if (!dir($directory)) {
- die("Directory Not Found");
- }
- $path = $_FILES['product_image']['name'];
- $ext = pathinfo($path, PATHINFO_EXTENSION);
- $target_file = $directory . "product_" . uniqid() . "." . $ext;
- $file_type = pathinfo($target_file, PATHINFO_EXTENSION);
- $file_size = $_FILES['product_image']['size'];
- $is_image = getimagesize($_FILES['product_image']['tmp_name']);
- if ($is_image) {
- if (file_exists($target_file)) {
- echo 'This file Already exists';
- exit();
- } else {
- if ($file_size > 5242880) {
- echo 'File Size is Too Large.Please select a size within 5mb';
- exit();
- } else {
- if ($file_type != 'jpg' && $file_type != 'png') {
- die("File type is not vaild");
- } else {
- if (move_uploaded_file($_FILES['product_image']['tmp_name'], $target_file)) {
- $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]')";
- if (mysqli_query($this->connect(), $sql)) {
- $message = "Product Informations Successfully Saved";
- return $message;
- } else {
- die("Query Problem") . mysqli_error($this->connect());
- }
- } else {
- die("Product Image Upload Error");
- }
- }
- }
- }
- } else {
- echo 'This is not a image';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement