-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
45 lines (40 loc) · 1.6 KB
/
upload.php
File metadata and controls
45 lines (40 loc) · 1.6 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
<?php
// Disable CORS
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if a file was uploaded
if (isset($_FILES['zipFile']) && $_FILES['zipFile']['error'] === UPLOAD_ERR_OK) {
// Check file size (50KB limit)
if ($_FILES['zipFile']['size'] > 51200) { // 50KB = 50 * 1024 bytes
echo 'File size exceeds the 50KB limit.';
exit;
}
$uploadDir = 'uploads/'; // Directory where files will be saved
$originalName = pathinfo($_FILES['zipFile']['name'], PATHINFO_FILENAME);
$extension = pathinfo($_FILES['zipFile']['name'], PATHINFO_EXTENSION);
$uploadFile = $uploadDir . $_FILES['zipFile']['name'];
// Ensure the upload directory exists
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
// Check if file exists and append a number if necessary
$counter = 1;
while (file_exists($uploadFile)) {
$uploadFile = $uploadDir . $originalName . '_' . $counter . '.' . $extension;
$counter++;
}
// Move the uploaded file to the desired directory
if (move_uploaded_file($_FILES['zipFile']['tmp_name'], $uploadFile)) {
echo 'File successfully uploaded as ' . basename($uploadFile);
} else {
echo 'Failed to move uploaded file.';
}
} else {
echo 'No file uploaded or upload error.';
}
} else {
echo 'Invalid request method.';
}
?>