forked from gdgpescara/app-mod-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
24 lines (21 loc) · 751 Bytes
/
upload.php
File metadata and controls
24 lines (21 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
include 'config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['image'])) {
$filename = 'uploads/' . basename($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $filename)) {
$stmt = $pdo->prepare("INSERT INTO images (user_id, filename) VALUES (?, ?)");
$stmt->execute([$_SESSION['user_id'], $filename]);
echo "Immagine caricata con successo!";
} else {
echo "Errore nel caricamento dell'immagine.";
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image" required />
<button type="submit">Carica Immagine</button>
</form>