-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
48 lines (42 loc) · 1.49 KB
/
Copy pathupload.php
File metadata and controls
48 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// ======= Beállítások =======
$uploadDir = '../upload/'; // ide menti a fájlokat
$maxFileSize = 20 * 1024 * 1024; // max 20 MB
// ======= Könyvtár létrehozása, ha nem létezik =======
if (!file_exists($uploadDir)) {
if (!mkdir($uploadDir, 0777, true)) {
die("Nem sikerült létrehozni a feltöltési mappát!");
}
}
// ======= Fájl feltöltés feldolgozása =======
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
$targetPath = $uploadDir . basename($file['name']);
if ($file['error'] !== UPLOAD_ERR_OK) {
die("Hiba a feltöltés során: " . $file['error']);
}
if ($file['size'] > $maxFileSize) {
die("A fájl túl nagy! (max " . ($maxFileSize / 1024 / 1024) . " MB)");
}
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
echo "<p style='color:green;'>Feltöltés sikeres: " . htmlspecialchars($file['name']) . "</p>";
} else {
echo "<p style='color:red;'>Sikertelen feltöltés.</p>";
}
}
?>
<!-- ======= Egyszerű HTML űrlap ======= -->
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8">
<title>Fájl feltöltése</title>
</head>
<body style="font-family:sans-serif; margin:40px;">
<h2>Fájl feltöltése</h2>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit">Feltöltés</button>
</form>
</body>
</html>