1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
   |  
<?php
	error_reporting( ~E_NOTICE );
	require_once 'dbconfig.php';
	if(isset($_POST['btnsave']))
	{
    $catalogname = $_POST['catalog_name'];
    $catalogmaker = $_POST['catalog_maker'];
    $catalogtypes = $_POST['catalog_types'];
    $catalogscale = $_POST['catalog_scale'];
    $catalogedition = $_POST['catalog_edition'];
    $imgFile = $_FILES['profile_image']['name'];
    $tmp_dir = $_FILES['profile_image']['tmp_name'];
    $imgSize = $_FILES['profile_image']['size'];
    $imgFileProduct = $_FILES['product_image']['name'];
    $imgSizeProduct = $_FILES['product_image']['tmp_name'];
    $tmp_dirProduct = $_FILES['product_image']['size'];
	if(empty($catalogname)){
	    $errMSG = "Please Enter Product Name.";
		}
		else if(empty($catalogmaker)){
		    $errMSG = "Please Enter a Maker.";
		}
		else if(empty($catalogtypes)){
		    $errMSG = "Please Enter a Types.";
		}
		else if(empty($catalogscale)){
		    $errMSG = "Please Enter a Scale.";
		}
		else if(empty($catalogedition)){
		    $errMSG = "Please Enter a Edition.";
        }
		else if(empty($imgFile)){
		    $errMSG = "Please Select Image File.";
	    }
	    else if(empty($imgFileProduct)){
	        $errMSG = "Please Select Image File(s).";
	    }
		else {
	    {
	        $upload_dir = 'product_images/'; // upload directory
	        $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
	        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif');
	        $userpic= rand(1000,1000000).".".$imgExt;
	        if(in_array($imgExt, $valid_extensions)){
	            if($imgSize < 5000000){
	                move_uploaded_file($tmp_dir,$upload_dir.$userpic);
	            }
	            else{
	                $errMSG = "Sorry, your file is too large.";
 
	            }
 
	        }
	        else{
	            $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed3.";
 
	        }
 
	    }
	    if(!isset($errMSG)){
	        $stmt = $DB_con->prepare('INSERT INTO id_catalog(name,maker,types,scale,edition,pic) VALUES(:uname, :umaker, :utypes, :uscale, :uedition, :upic)');
	        $stmt->bindParam(':uname',$catalogname);
	        $stmt->bindParam(':umaker',$catalogmaker);
	        $stmt->bindParam(':utypes',$catalogtypes);
	        $stmt->bindParam(':uscale',$catalogscale);
	        $stmt->bindParam(':uedition',$catalogedition);
	        $stmt->bindParam(':upic',$userpic);
	        if($stmt->execute()){
	            $successMSG = "new record succesfully inserted ...";
	            header("refresh:5;index.php"); // redirects image view page after 5 seconds.
	            $last_id = $DB_con->lastInsertId();
	            echo "New record created successfully. Last inserted ID is: " . $last_id;
 
	        }
	        else{
	            $errMSG = "error while inserting....";
 
	        }
 
	    }
	    foreach($_FILES['product_image']['tmp_name'] as $key => $tmp_dirProduct ){
	        $imgFileProduct = $key.$_FILES['product_image']['name'][$key];
	        $imgSizeProduct =$_FILES['product_image']['size'][$key];
	        $tmp_dirProduct =$_FILES['product_image']['tmp_name'][$key];
	        $upload_dirProduct = 'product_images/';
	        $imgExtProduct = strtolower(pathinfo($imgFileProduct,PATHINFO_EXTENSION));
	        $valid_extensionsProduct = array('jpeg', 'jpg', 'png', 'gif');
	        $productpic= rand(1000,1000000).".".$imgExtProduct;
	        if(in_array($imgExtProduct, $valid_extensionsProduct)){
	            if($imgSizeProduct < 5000000){
	                move_uploaded_file($tmp_dirProduct,$upload_dirProduct.$productpic);
 
	            }
	            else{
	                $errMSG = "Sorry, your file is too large.";
 
	            }
 
	        }
	        else{
	            $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed2.";	
 
	        }
	        if(!isset($errMSG)){
	            $stmt1 = $DB_con->prepare('INSERT INTO id_images(name_pic) VALUES(:uproductpic)');
	            $stmt1->bindParam(':uproductpic',$productpic);
	            if($stmt1->execute()){
	                $successMSG = "new record succesfully inserted ...";
	                header("refresh:5;index.php"); // redirects image view page after 5 seconds.
	                $last_id = $DB_con->lastInsertId();
	                echo "New record created successfully. Last inserted ID is: " . $last_id;
 
	            }
	            else{
	                $errMSG = "error while inserting....";
 
	            }
 
	        }
 
	    }
 
		}
 
	}
?> | 
Partager