[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
repository_afbs
/
user
/
[
Home
]
File: upload.php
<?php session_start(); require_once 'config/database.php'; // Check if user is logged in if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'mahasiswa') { header("Location: login.php"); exit(); } $database = new Database(); $db = $database->getConnection(); $message = ''; $error = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $title = $_POST['title']; $abstract = $_POST['abstract']; $authors = $_POST['authors']; $year = $_POST['year']; $supervisor1 = $_POST['supervisor1']; $supervisor2 = $_POST['supervisor2']; $examiner1 = $_POST['examiner1']; $examiner2 = $_POST['examiner2']; $keywords = $_POST['keywords']; // Handle file upload $target_dir = "uploads/theses/"; if (!file_exists($target_dir)) { mkdir($target_dir, 0777, true); } $pdf_file = time() . '_' . basename($_FILES["pdf_file"]["name"]); $target_file = $target_dir . $pdf_file; // Handle cover image $cover_image = ''; if (isset($_FILES["cover_image"]) && $_FILES["cover_image"]["error"] == 0) { $cover_image = time() . '_cover_' . basename($_FILES["cover_image"]["name"]); $cover_target = $target_dir . $cover_image; move_uploaded_file($_FILES["cover_image"]["tmp_name"], $cover_target); } // Validate file type $fileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); if ($fileType != "pdf") { $error = "Hanya file PDF yang diperbolehkan!"; } else { if (move_uploaded_file($_FILES["pdf_file"]["tmp_name"], $target_file)) { // Insert into database $query = "INSERT INTO theses (title, abstract, author_id, authors, year, supervisor1, supervisor2, examiner1, examiner2, keywords, pdf_file, cover_image, status) VALUES (:title, :abstract, :author_id, :authors, :year, :supervisor1, :supervisor2, :examiner1, :examiner2, :keywords, :pdf_file, :cover_image, 'pending')"; $stmt = $db->prepare($query); $stmt->bindParam(':title', $title); $stmt->bindParam(':abstract', $abstract); $stmt->bindParam(':author_id', $_SESSION['user_id']); $stmt->bindParam(':authors', $authors); $stmt->bindParam(':year', $year); $stmt->bindParam(':supervisor1', $supervisor1); $stmt->bindParam(':supervisor2', $supervisor2); $stmt->bindParam(':examiner1', $examiner1); $stmt->bindParam(':examiner2', $examiner2); $stmt->bindParam(':keywords', $keywords); $stmt->bindParam(':pdf_file', $pdf_file); $stmt->bindParam(':cover_image', $cover_image); if ($stmt->execute()) { $message = "Tugas akhir berhasil diupload dan sedang menunggu persetujuan admin!"; } else { $error = "Gagal menyimpan data ke database!"; } } else { $error = "Gagal mengupload file!"; } } } ?> <!DOCTYPE html> <html lang="id"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Upload Tugas Akhir - Repository AFBS</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> </head> <body> <!-- Navigation --> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class="container"> <a class="navbar-brand" href="index.php">Repository AFBS</a> <div class="collapse navbar-collapse"> <ul class="navbar-nav ms-auto"> <li class="nav-item"> <a class="nav-link" href="index.php">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="my_uploads.php">Uploads Saya</a> </li> <li class="nav-item"> <a class="nav-link" href="logout.php">Logout</a> </li> </ul> </div> </div> </nav> <div class="container my-5"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header bg-primary text-white"> <h4 class="mb-0"><i class="fas fa-upload"></i> Upload Tugas Akhir</h4> </div> <div class="card-body"> <?php if($message): ?> <div class="alert alert-success"><?php echo $message; ?></div> <?php endif; ?> <?php if($error): ?> <div class="alert alert-danger"><?php echo $error; ?></div> <?php endif; ?> <form action="upload.php" method="POST" enctype="multipart/form-data"> <div class="mb-3"> <label for="title" class="form-label">Judul Tugas Akhir *</label> <input type="text" class="form-control" id="title" name="title" required> </div> <div class="mb-3"> <label for="abstract" class="form-label">Abstrak *</label> <textarea class="form-control" id="abstract" name="abstract" rows="6" required></textarea> <div class="form-text">Minimal 150 kata, maksimal 500 kata.</div> </div> <div class="mb-3"> <label for="authors" class="form-label">Nama Lengkap Penulis *</label> <input type="text" class="form-control" id="authors" name="authors" value="<?php echo $_SESSION['full_name']; ?>" required> </div> <div class="mb-3"> <label for="year" class="form-label">Tahun *</label> <select class="form-control" id="year" name="year" required> <?php for($y = date('Y'); $y >= 2015; $y--): ?> <option value="<?php echo $y; ?>"><?php echo $y; ?></option> <?php endfor; ?> </select> </div> <div class="row"> <div class="col-md-6 mb-3"> <label for="supervisor1" class="form-label">Pembimbing 1 *</label> <input type="text" class="form-control" id="supervisor1" name="supervisor1" required> </div> <div class="col-md-6 mb-3"> <label for="supervisor2" class="form-label">Pembimbing 2</label> <input type="text" class="form-control" id="supervisor2" name="supervisor2"> </div> </div> <div class="row"> <div class="col-md-6 mb-3"> <label for="examiner1" class="form-label">Penguji 1 *</label> <input type="text" class="form-control" id="examiner1" name="examiner1" required> </div> <div class="col-md-6 mb-3"> <label for="examiner2" class="form-label">Penguji 2</label> <input type="text" class="form-control" id="examiner2" name="examiner2"> </div> </div> <div class="mb-3"> <label for="keywords" class="form-label">Kata Kunci *</label> <input type="text" class="form-control" id="keywords" name="keywords" placeholder="Contoh: Farmasi, Antibiotik, Tanaman Obat" required> <div class="form-text">Pisahkan dengan koma (,)</div> </div> <div class="mb-3"> <label for="cover_image" class="form-label">Sampul/Cover (Opsional)</label> <input type="file" class="form-control" id="cover_image" name="cover_image" accept="image/*"> </div> <div class="mb-3"> <label for="pdf_file" class="form-label">File PDF Tugas Akhir *</label> <input type="file" class="form-control" id="pdf_file" name="pdf_file" accept=".pdf" required> <div class="form-text">Maksimal ukuran file: 20MB</div> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" id="agreement" required> <label class="form-check-label" for="agreement"> Saya menyatakan bahwa tugas akhir ini adalah karya orisinal saya dan tidak melanggar hak cipta pihak lain. </label> </div> <button type="submit" class="btn btn-primary w-100"> <i class="fas fa-cloud-upload-alt"></i> Upload Tugas Akhir </button> </form> </div> </div> </div> </div> </div> </body> </html>