Upload a File
5000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats (you can modify this as needed)
$allowedTypes = ['jpg', 'png', 'jpeg', 'gif', 'pdf', 'txt'];
if (!in_array($fileType, $allowedTypes)) {
echo "Sorry, only JPG, JPEG, PNG, GIF, PDF & TXT files are allowed.";
$uploadOk = 0;
}
// Check if everything is ok to upload the file
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
?>