403Webshell
Server IP : 188.114.96.3  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64
User :  ( 3194769)
PHP Version : 8.5.12
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /polana/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /polana/admin/media.php
<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/includes/import_menu.php';
require_login();
ensure_import_schema();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    verify_csrf();
    $action = (string)($_POST['action'] ?? '');

    if ($action === 'upload') {
        try {
            $files = normalize_multi_uploads($_FILES['images'] ?? []);
            if (!$files) {
                throw new RuntimeException('Wybierz przynajmniej jedno zdjęcie.');
            }

            $altBase = trim((string)($_POST['alt_text'] ?? ''));
            $count = 0;

            foreach ($files as $file) {
                $alt = $altBase;

                if ($alt === '') {
                    $base = pathinfo((string)$file['name'], PATHINFO_FILENAME);
                    $base = preg_replace('/[_-]+/', ' ', $base) ?? $base;
                    $alt = trim($base);
                }

                store_media_file($file, $alt);
                $count++;
            }

            admin_log('media_upload', 'Dodano zdjęcia: ' . $count);
            flash('success', "Dodano {$count} zdjęć.");
            redirect('/admin/media.php');
        } catch (Throwable $e) {
            flash('error', $e->getMessage());
            redirect('/admin/media.php');
        }
    }

    if ($action === 'save_alt') {
        $id = (int)($_POST['id'] ?? 0);
        $alt = trim((string)($_POST['alt_text'] ?? ''));

        $stmt = db()->prepare('UPDATE media_library SET alt_text=? WHERE id=?');
        $stmt->execute([$alt, $id]);

        flash('success', 'Opis zdjęcia zapisany.');
        redirect('/admin/media.php');
    }

    if ($action === 'delete') {
        $id = (int)($_POST['id'] ?? 0);

        $stmt = db()->prepare('SELECT file_path FROM media_library WHERE id=?');
        $stmt->execute([$id]);
        $path = $stmt->fetchColumn();

        $stmt = db()->prepare('DELETE FROM media_library WHERE id=?');
        $stmt->execute([$id]);

        if (is_string($path) && str_starts_with($path, '/uploads/dishes/')) {
            $absolute = dirname(__DIR__) . $path;
            if (is_file($absolute)) {
                @unlink($absolute);
            }
        }

        flash('success', 'Zdjęcie usunięte z biblioteki.');
        redirect('/admin/media.php');
    }
}

$media = media_library(150);

render_admin_header('Zdjęcia');
?>
<div class="admin-title-row">
    <div>
        <h1>Zdjęcia</h1>
        <p>Wrzucaj zdjęcia dań i wnętrza. Możesz później przypisać je do pozycji menu.</p>
    </div>
    <a class="btn btn-light" href="/admin/import.php">← Import Word</a>
</div>

<form class="form-card form-grid" method="post" enctype="multipart/form-data">
    <?= csrf_field() ?>
    <input type="hidden" name="action" value="upload">

    <label class="full">
        Zdjęcia JPG / PNG / WebP
        <input type="file" name="images[]" accept="image/jpeg,image/png,image/webp" multiple required>
    </label>

    <label class="full">
        ALT dla całej paczki – opcjonalnie
        <input name="alt_text" placeholder="np. Dania w Mojej Polanie Smaków">
        <span class="muted">Jeśli zostawisz puste, ALT powstanie z nazwy pliku.</span>
    </label>

    <div class="full">
        <button class="btn btn-primary" type="submit">Wgraj zdjęcia</button>
    </div>
</form>

<?php if (!$media): ?>
    <div class="card"><p class="muted">Nie ma jeszcze zdjęć.</p></div>
<?php else: ?>
    <div class="media-grid">
        <?php foreach ($media as $image): ?>
            <article class="media-card">
                <img src="<?= e($image['file_path']) ?>" alt="<?= e($image['alt_text']) ?>" loading="lazy">

                <form method="post" class="media-meta">
                    <?= csrf_field() ?>
                    <input type="hidden" name="action" value="save_alt">
                    <input type="hidden" name="id" value="<?= (int)$image['id'] ?>">

                    <label>
                        ALT / opis zdjęcia
                        <input name="alt_text" value="<?= e($image['alt_text']) ?>">
                    </label>

                    <button class="btn btn-small btn-light" type="submit">Zapisz ALT</button>
                </form>

                <div class="media-path"><?= e($image['file_path']) ?></div>

                <form method="post" onsubmit="return confirm('Usunąć zdjęcie?')">
                    <?= csrf_field() ?>
                    <input type="hidden" name="action" value="delete">
                    <input type="hidden" name="id" value="<?= (int)$image['id'] ?>">
                    <button class="btn btn-small btn-danger" type="submit">Usuń</button>
                </form>
            </article>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php render_admin_footer(); ?>

Youez - 2016 - github.com/yon3zu
LinuXploit