-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
25 lines (20 loc) · 739 Bytes
/
process.php
File metadata and controls
25 lines (20 loc) · 739 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
$targetDir = "uploads/";
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
$targetFile = $targetDir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// Optional: restrict file types
$allowed = ['txt', 'html', 'csv', 'xml', 'json'];
if (!in_array($fileType, $allowed)) {
echo "Sorry, only " . implode(", ", $allowed) . " files are allowed.";
$uploadOk = 0;
}
if ($uploadOk && move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
?>