<!DOCTYPE html>
<html>
<head>
<title>Upload File</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["file"])) {
$targetDir = "uploads/"; // Thư mục lưu trữ tệp
$targetFile = $targetDir . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
echo "Tệp " . htmlspecialchars(basename($_FILES["file"]["name"])) . " đã được tải lên thành công.";
} else {
echo "Có lỗi xảy ra khi tải lên tệp.";
}
}
?>
<form method="post" enctype="multipart/form-data">
Chọn tệp để tải lên: <input type="file" name="file" id="file">
<input type="submit" value="Tải lên">
</form>
</body>
</html>