D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
tapaslight.encodersunlimited.com
/
tadminl
/
Filename :
add_testimonial.php
back
Copy
<?php include 'config.php'; // Include database connection file // Handle form submission and image upload if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['addtestimonial'])) { $name = $_POST['name']; $comment = $_POST['comment']; if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK) { $imagePath = image_upload($_FILES['image']); if ($imagePath !== false) { $query = "INSERT INTO testimonial (name, image, comment) VALUES (?, ?, ?)"; $stmt = $conn->prepare($query); $stmt->bind_param('sss', $name, $imagePath, $comment); if ($stmt->execute()) { echo "New testimonial added successfully."; } else { echo "Error: " . $stmt->error; } } } else { echo "Error: No file uploaded or file upload error."; } } function image_upload($file) { $targetDir = "uploads/"; $targetFile = $targetDir . basename($file["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); // Check if image file is an actual image or fake image $check = getimagesize($file["tmp_name"]); if ($check === false) { echo "File is not an image."; $uploadOk = 0; } // Check file size (limit to 5MB) if ($file["size"] > 5000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats $allowedTypes = ['jpg', 'jpeg', 'png', 'gif', 'svg']; if (!in_array($imageFileType, $allowedTypes)) { echo "Sorry, only JPG, JPEG, PNG, GIF & SVG files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { return false; } else { if (move_uploaded_file($file["tmp_name"], $targetFile)) { return $targetFile; } else { echo "Sorry, there was an error uploading your file."; return false; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include 'style.php'; ?> </head> <body> <!-- loader starts--> <div class="loader-wrapper"> <div class="loader"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> </div> <!-- loader ends--> <!-- tap on top starts--> <div class="tap-top"><i data-feather="chevrons-up"></i></div> <!-- tap on tap ends--> <!-- page-wrapper Start--> <div class="page-wrapper default-wrapper" id="pageWrapper"> <!-- Page Header Start--> <div class="page-header"> <div class="header-wrapper row m-0"> <div class="header-logo-wrapper col-auto p-0"> <div class="logo-wrapper"> <a href="index.php"> <img class="img-fluid for-light" src="assets/images/ashwikalogo.png" alt=""> <img class="img-fluid for-dark" src="assets/images/ashwikalogo.png" alt=""> </a> </div> </div> <div class="left-header col-xxl-5 col-xl-6 col-md-4 col-auto box-col-6 horizontal-wrapper p-0"> <div class="left-menu-header"> <ul class="header-left"> <li> <div class="form-group w-100"> <div class="Typeahead Typeahead--twitterUsers"> <div class="u-posRelative d-flex"> <input class="demo-input py-0 Typeahead-input form-control-plaintext w-100" type="text" placeholder="Search anything..." name="q" title=""> </div> </div> </div> </li> </ul> </div> </div> <div class="nav-right col-xxl-7 col-xl-6 col-auto box-col-6 pull-right right-header p-0 ms-auto"> <ul class="nav-menus"> <li class="serchinput"> <div class="serchbox"> <svg> <use href="https://admin.pixelstrap.net/crocsassets/svg/icon-sprite.svg#fill-search"></use> </svg> </div> <div class="form-group search-form"> <input type="text" placeholder="Search here..."> </div> </li> <li> <div class="mode"> <i class="fa-solid fa-circle-half-stroke"></i> </div> </li> <li class="profile-nav onhover-dropdown p-0"> <div class="d-flex align-items-center profile-media"> <img class="b-r-10 img-40" src="assets/images/dashboard/profile.png" alt=""> <div class="flex-grow-1"> <span>Ashwika Diamonds</span> <p class="mb-0">Welcome Admin</p> </div> </div> </li> </ul> </div> </div> </div> <!-- Page Header Ends --> <!-- Page Body Start--> <div class="page-body-wrapper default-menu default-menu"> <!-- Page Sidebar Start--> <?php include 'sidebar.php'; ?> <!-- Page Sidebar Ends--> <div class="page-body"> <div class="container-fluid"> <div class="page-title"> <div class="row"> <div class="col-sm-6 ps-0"> <h3>Create Testimonial</h3> </div> </div> </div> </div> <!-- Container-fluid starts--> <form action="crud.php" method="POST" enctype="multipart/form-data"> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="card"> <div class="card-body"> <div class="form theme-form"> <div class="row"> <div class="col"> <div class="mb-3"> <label>Name</label> <input class="form-control" type="text" name="name" placeholder="Name *" required> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Comment</label> <textarea class="form-control" name="comment" rows="4" placeholder="Comment *" required></textarea> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Designation</label> <input class="form-control" type="text" name="designation" placeholder="Designation *" required> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Upload Image</label> <h4>Drop files here or click to upload.</h4> <input type="file" name="image" class="form-control" accept=".jpg, .jpeg, .png, .svg" required> </div> </div> </div> <div class="row"> <div class="col"> <button type="submit" class="btn btn-success" name="addtestimonial">Create Testimonial</button> <button type="reset" class="btn btn-outline-secondary">Cancel</button> </div> </div> </div> </div> </div> </div> </div> </div> </form> <!-- Container-fluid Ends--> </div> <!-- footer start--> <?php include 'footer.php'; ?> </div> </div> </body> </html>