-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
31 lines (25 loc) · 919 Bytes
/
Copy pathupload.php
File metadata and controls
31 lines (25 loc) · 919 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
25
26
27
28
29
30
31
<?php
header('Content-Type: application/json');
$uploadDir = 'uploads/';
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
if (!isset($_FILES['file'])) {
echo json_encode(['error' => 'هیچ فایلی انتخاب نشده است.']);
exit;
}
$file = $_FILES['file'];
$fileName = $file['name'];
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$forbiddenExtensions = ['php', 'html'];
if (in_array($fileExtension, $forbiddenExtensions)) {
echo json_encode(['error' => 'فایلهای PHP و HTML مجاز نیستند.']);
exit;
}
$destination = $uploadDir . uniqid() . '_' . $fileName;
if (move_uploaded_file($file['tmp_name'], $destination)) {
echo json_encode(['message' => "فایل $fileName با موفقیت آپلود شد!"]);
} else {
echo json_encode(['error' => 'خطا در آپلود فایل.']);
}
?>