Skip to content

Commit d149348

Browse files
committed
---
1 parent da9cfc2 commit d149348

File tree

11 files changed

+9336
-0
lines changed

11 files changed

+9336
-0
lines changed

Mini Project/DB/phpproject.sql

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 5.1.1
3+
-- https://www.phpmyadmin.net/
4+
--
5+
-- Host: 127.0.0.1
6+
-- Generation Time: May 16, 2022 at 06:31 AM
7+
-- Server version: 10.4.22-MariaDB
8+
-- PHP Version: 8.0.13
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
START TRANSACTION;
12+
SET time_zone = "+00:00";
13+
14+
15+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
16+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
17+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
18+
/*!40101 SET NAMES utf8mb4 */;
19+
20+
--
21+
-- Database: `phpproject`
22+
--
23+
24+
-- --------------------------------------------------------
25+
26+
--
27+
-- Table structure for table `employees`
28+
--
29+
30+
CREATE TABLE `employees` (
31+
`id` int(11) NOT NULL,
32+
`name` text NOT NULL,
33+
`email` text NOT NULL
34+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
35+
36+
--
37+
-- Dumping data for table `employees`
38+
--
39+
40+
INSERT INTO `employees` (`id`, `name`, `email`) VALUES
41+
(1, 'user 01', 'user01@mail.com'),
42+
(2, 'user 02', 'user02@mail.com'),
43+
(3, 'user 03', 'user03@mail.com'),
44+
(4, 'user 04', 'user04@mail.com'),
45+
(5, 'user 05', 'user05@mail.com'),
46+
(6, 'user 06', 'user06@mail.com'),
47+
(7, 'user 07', 'user07@mail.com'),
48+
(8, 'user 08', 'user08@mail.com'),
49+
(9, 'user 09', 'user09@mail.com'),
50+
(10, 'user 10', 'user10@mail.com'),
51+
(11, 'user 11', 'user11@mail.com'),
52+
(12, 'user 12', 'user12@mail.com'),
53+
(13, 'user 13', 'user13@mail.com'),
54+
(14, 'user 14', 'user14@mail.com'),
55+
(15, 'user 15', 'user15@mail.com'),
56+
(16, 'user 16', 'user16@mail.com'),
57+
(17, 'user 17', 'user17@mail.com'),
58+
(18, 'user 18', 'user18@mail.com'),
59+
(19, 'user 19', 'user19@mail.com'),
60+
(20, 'user 20', 'user20@mail.com');
61+
62+
-- --------------------------------------------------------
63+
64+
--
65+
-- Table structure for table `products`
66+
--
67+
68+
CREATE TABLE `products` (
69+
`id` int(11) NOT NULL,
70+
`product` varchar(255) NOT NULL,
71+
`images` varchar(255) NOT NULL
72+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
73+
74+
--
75+
-- Dumping data for table `products`
76+
--
77+
78+
INSERT INTO `products` (`id`, `product`, `images`) VALUES
79+
(1, 'product 1', 'mobile.jpg'),
80+
(2, 'product 1', 'scaler.jpg'),
81+
(3, 'product 1', 'moister.jpg'),
82+
(4, 'Ohim', 'smiling-1280975_1920.jpg'),
83+
(5, 'Ohim', '7.jpg');
84+
85+
--
86+
-- Indexes for dumped tables
87+
--
88+
89+
--
90+
-- Indexes for table `employees`
91+
--
92+
ALTER TABLE `employees`
93+
ADD PRIMARY KEY (`id`);
94+
95+
--
96+
-- Indexes for table `products`
97+
--
98+
ALTER TABLE `products`
99+
ADD PRIMARY KEY (`id`);
100+
101+
--
102+
-- AUTO_INCREMENT for dumped tables
103+
--
104+
105+
--
106+
-- AUTO_INCREMENT for table `employees`
107+
--
108+
ALTER TABLE `employees`
109+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;
110+
111+
--
112+
-- AUTO_INCREMENT for table `products`
113+
--
114+
ALTER TABLE `products`
115+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
116+
COMMIT;
117+
118+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
119+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
120+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
if(isset($_POST['saveProductBtn'])){
4+
include_once ('../config/db.php');
5+
6+
$product = $_POST['productName'];
7+
8+
$uploadFolder = '../img/product/';
9+
$allowTypes = array('jpg','png','jpeg','gif');
10+
11+
$allOk = 0;
12+
13+
foreach ($_FILES['imageFile']['tmp_name'] as $key => $image) {
14+
15+
$imageFile = $_FILES['imageFile']['tmp_name'][$key]; // file here
16+
$imageName = $_FILES['imageFile']['name'][$key]; // file name here
17+
$fileType = pathinfo($imageName, PATHINFO_EXTENSION); // file extension here
18+
19+
echo "'.$imageFile.'"." || "."'$imageName'"." || "."'$fileType'"."<br>";
20+
21+
// checking file type
22+
if(!in_array($fileType, $allowTypes)){
23+
$allOk = 1;
24+
echo "Only 'jpg','png','jpeg','gif' support.";
25+
exit();
26+
}
27+
28+
// save to database
29+
$result = $conn->query("INSERT INTO products (`product`,`images`) VALUE ('$product','$imageName')") or die("Error in saving image".$conn->error);
30+
31+
if($result){
32+
move_uploaded_file($imageFile,$uploadFolder.$imageName); // move images to folder
33+
}
34+
}
35+
36+
if ($allOk == 0) {
37+
echo "Images uploaded successfully !";
38+
}else{
39+
echo "Something went wrong";
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
$host = 'localhost';
3+
$dbname = 'phpproject';
4+
$user = 'root';
5+
$pass = '';
6+
7+
try {
8+
$conn = new mysqli($host, $user, $pass, $dbname);
9+
} catch (\mysqli_sql_exception $e) {
10+
throw new \mysqli_sql_exception($e->getMessage(), $e->getCode());
11+
}
12+
// OR
13+
// Check connection
14+
/*if ($conn->connect_error) {
15+
die("Connection failed: " . $conn->connect_error);
16+
}*/
17+
18+
unset($host, $dbname, $user, $pass);
2.86 KB
Loading
356 KB
Loading
41.2 KB
Loading
842 KB
Loading

Mini Project/imageInsert/index.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php session_start(); ?>
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>PHP - Multiple Image Insertion</title>
9+
<link rel="icon" type="image/x-icon" href="img/favicon/favicon.jpg">
10+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
11+
<link rel="stylesheet" href="assets/css/style.css">
12+
</head>
13+
<body>
14+
<section>
15+
<div class="container my-5">
16+
<h2>Product Register Form</h2>
17+
<form class="row g-3" action="actions/imageInsert.php" method="post" enctype="multipart/form-data">
18+
<div class="col-md-12">
19+
<label class="form-label">Product Name*</label>
20+
<input type="text" class="form-control" name="productName" required>
21+
</div>
22+
<div class="col-12">
23+
<label class="form-label">Upload Image*</label>
24+
<input class="form-control" type="file" name="imageFile[]" multiple required>
25+
</div>
26+
<div class="col-12">
27+
<button type="submit" class="btn btn-primary" name="saveProductBtn">Save</button>
28+
</div>
29+
</form>
30+
</div>
31+
</section>
32+
33+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)