PHP 8.5.2
Preview: edit-video.php Size: 4.14 KB
/home/serveshikshafoundation/htdocs/serveshikshafoundation.org.in/admin/html/edit-video.php

<?php
include('auth.php');
include('connection.php');

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    // Fetch existing video details
    $query = "SELECT * FROM videos WHERE id = $id";
    $result = mysqli_query($conn, $query);

    if ($result && mysqli_num_rows($result) > 0) {
        $video = mysqli_fetch_assoc($result);
    } else {
        echo "<script>
                alert('Video not found!');
                window.location.href = 'video-gallery.php';
              </script>";
        exit;
    }
}

$updateSuccess = false; // Variable to track success

// Update video
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $newVideo = $_FILES['video']['name'];
    $targetDir = "assets/img/videos/";
    $targetFile = $targetDir . time() . "_" . basename($newVideo);

    if (!empty($newVideo)) {
        // Delete old video file
        if (file_exists($video['video_url'])) {
            unlink($video['video_url']);
        }

        // Upload new video
        if (move_uploaded_file($_FILES['video']['tmp_name'], $targetFile)) {
            // Update database with new video URL
            $updateQuery = "UPDATE videos SET video_url = '$targetFile' WHERE id = $id";
            if (mysqli_query($conn, $updateQuery)) {
                $updateSuccess = true; // Mark update success
            } else {
                echo "<script>alert('Error updating video!');</script>";
            }
        } else {
            echo "<script>alert('Failed to upload video!');</script>";
        }
    } else {
        echo "<script>alert('Please select a video to upload!');</script>";
    }
}
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin</title>
    <link rel="stylesheet" href="../assets/css/styles.min.css" />
    <!-- Include SweetAlert2 -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>

<body>
    <div class="page-wrapper" id="main-wrapper" data-layout="vertical" data-navbarbg="skin6" data-sidebartype="full"
        data-sidebar-position="fixed" data-header-position="fixed">

        <?php include('aside.php') ?>

        <div class="body-wrapper">
            <?php include('header.php'); ?>

            <div class="container-fluid mt-5">
                <h2 class="mb-4">Edit Video</h2>

                <form action="" method="POST" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label class="form-label">Current Video:</label><br>
                        <video width="300" height="180" controls>
                            <source src="<?php echo $video['video_url']; ?>" type="video/mp4">
                            Your browser does not support the video tag.
                        </video>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Upload New Video:</label>
                        <input type="file" name="video" class="form-control" accept="video/mp4">
                    </div>

                    <button type="submit" class="btn btn-primary">Update Video</button>
                    <a href="video-gallery.php" class="btn btn-secondary">Cancel</a>
                </form>
            </div>

        </div>
    </div>

    <script src="../assets/libs/jquery/dist/jquery.min.js"></script>
    <script src="../assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="../assets/js/sidebarmenu.js"></script>
    <script src="../assets/js/app.min.js"></script>
    <script src="../assets/libs/simplebar/dist/simplebar.js"></script>

    <!-- SweetAlert Success Notification -->
    <?php if ($updateSuccess) : ?>
        <script>
            Swal.fire({
                title: 'Video updated successfully!',
                icon: 'success',
                showConfirmButton: false,
                timer: 2000
            }).then(() => {
                window.location.href = 'video-gallery.php';
            });
        </script>
    <?php endif; ?>

</body>
</html>

Directory Contents

Dirs: 11 × Files: 30

Name Size Perms Modified Actions
- drwxr-xr-x 2025-04-05 16:58:42
Edit Download
assets DIR
- drwxr-xr-x 2025-04-05 16:58:42
Edit Download
baby-dec DIR
- drwxr-xr-x 2025-04-05 16:58:42
Edit Download
- drwxr-xr-x 2025-04-05 16:58:42
Edit Download
- drwxr-xr-x 2025-04-05 16:58:44
Edit Download
- drwxr-xr-x 2025-04-05 16:58:44
Edit Download
- drwxr-xr-x 2025-04-05 16:58:44
Edit Download
- drwxr-xr-x 2025-04-05 16:58:44
Edit Download
- drwxr-xr-x 2025-04-05 16:58:44
Edit Download
- drwxr-xr-x 2025-04-05 16:58:46
Edit Download
- drwxr-xr-x 2025-04-05 16:58:46
Edit Download
8.63 KB lrw-r----- 2025-04-06 01:10:32
Edit Download
8.49 KB lrw-r----- 2025-04-05 20:17:06
Edit Download
8.33 KB lrw-r----- 2025-04-01 18:04:14
Edit Download
4.67 KB lrw-r----- 2025-07-01 06:02:29
Edit Download
6.91 KB lrw-r----- 2025-04-07 09:05:32
Edit Download
4.59 KB lrw-r----- 2025-07-01 06:36:30
Edit Download
164 B lrw-r----- 2025-04-05 17:07:44
Edit Download
471 B lrw-r----- 2026-04-07 07:13:01
Edit Download
4.07 KB lrw-r----- 2025-04-07 18:20:40
Edit Download
1.62 KB lrw-r----- 2025-03-31 20:18:28
Edit Download
1.92 KB lrw-r----- 2025-04-01 00:02:56
Edit Download
1.93 KB lrw-r----- 2025-04-01 18:10:28
Edit Download
1.20 KB lrw-r----- 2025-04-02 21:38:00
Edit Download
1.94 KB lrw-r----- 2025-04-06 00:58:20
Edit Download
1.62 KB lrw-r----- 2025-07-01 06:05:36
Edit Download
1.67 KB lrw-r----- 2025-03-31 21:50:12
Edit Download
3.15 KB lrw-r----- 2025-04-02 22:26:14
Edit Download
5.43 KB lrw-r----- 2025-04-22 13:05:58
Edit Download
6.16 KB lrw-r----- 2025-04-05 20:16:08
Edit Download
6.18 KB lrw-r----- 2025-04-02 20:43:44
Edit Download
5.88 KB lrw-r----- 2025-04-02 21:46:38
Edit Download
3.17 KB lrw-r----- 2025-07-01 06:17:56
Edit Download
4.14 KB lrw-r----- 2025-03-31 22:30:04
Edit Download
551.14 KB lrw-r--r-- 2025-03-29 19:52:38
Edit Download
3.14 KB lrw-r----- 2025-06-28 23:18:18
Edit Download
4.67 KB lrw-r----- 2025-04-02 22:16:18
Edit Download
7.83 KB lrw-r----- 2025-04-05 23:49:56
Edit Download
3.15 KB lrw-r----- 2025-04-07 18:21:46
Edit Download
120 B lrw-r----- 2024-07-06 23:58:34
Edit Download
5.12 KB lrw-r----- 2025-03-31 22:33:26
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).