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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| <?php
error_reporting( ~E_NOTICE ); // avoid notice
require_once 'dbconfig.php';
if(isset($_POST['btnsave']))
{
$catalogname = $_POST['catalog_name'];// user name
$catalogmaker = $_POST['catalog_maker'];// user email
$catalogtypes = $_POST['catalog_types'];// user email
$catalogscale = $_POST['catalog_scale'];// user email
$catalogedition = $_POST['catalog_edition'];// user email
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
//2nd upload
for ($i=0; $i < count ($_FILES['product_image']['name']); $i++)
{
$imgFile_Product = $_FILES['product_image']['name'][$i];
$tmp_dir_Product = $_FILES['product_image']['tmp_name'][$i];
$imgSize_Product = $_FILES['product_image']['size'][$i];
}
//2nd upload
if(empty($catalogname))
{
$errMSG = "Please Enter Username.";
}
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($imgFile_Product)){
$errMSG = "Please Select Image File(s) Product.";
}
else
{
$upload_dir = 'user_images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
// rename uploading image
$userpic = rand(1000,1000000).".".$imgExt;
// allow valid image file formats
if(in_array($imgExt, $valid_extensions))
{
// Check file size '5MB'
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 allowed.";
}
}
// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('INSERT INTO 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);
//2nd upload
//$stmt = $DB_con->prepare('INSERT INTO pics (id_catalogue, file_name) VALUES ((SELECT id FROM catalog WHERE id=LAST_INSERT_ID()), :ufile_name)');
//$stmt->bindParam(':ufile_name',$productpic);
//2nd upload
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....";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1 class="h2">add new user. <a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-eye-open"></span> view all </a></h1>
</div>
<?php
if(isset($errMSG)){
?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <strong><?php echo $errMSG; ?></strong>
</div>
<?php
}
else if(isset($successMSG)){
?>
<div class="alert alert-success">
<strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
</div>
<?php
}
?>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<table class="table table-bordered table-responsive">
<tr>
<td><label class="control-label">Product Name.</label></td>
<td><input class="form-control" type="text" name="catalog_name" placeholder="Enter Product Name" value="<?php echo $catalogname; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">Maker.</label></td>
<td><input class="form-control" type="text" name="catalog_maker" placeholder="Maker of the Product" value="<?php echo $catalogmaker; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">Types.</label></td>
<td><input class="form-control" type="text" name="catalog_types" placeholder="Types of the Product" value="<?php echo $catalogtypes; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">Scale.</label></td>
<td><input class="form-control" type="text" name="catalog_scale" placeholder="Scale of the Product" value="<?php echo $catalogscale; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">Edition.</label></td>
<td><input class="form-control" type="text" name="catalog_edition" placeholder="Edition of the Product" value="<?php echo $catalogedition; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">Profile Img.</label></td>
<td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
</tr>
<tr>
<td><label class="control-label">Upload Pics.</label></td>
<td><input class="input-group" type="file" name="product_image" multiple accept="image/*" /></td>
</tr>
<tr>
<td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
<span class="glyphicon glyphicon-save"></span> save
</button>
</td>
</tr>
</table>
</form>
</div>
<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html> |
Partager