Upload a File
10000000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats (optional)
$allowedTypes = ['jpg', 'png', 'gif', 'pdf', 'txt','zip','rar'];
if (!in_array($fileType, $allowedTypes)) {
echo "Sorry, only JPG, PNG, GIF, PDF, & TXT files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (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.";
}
}
}
?>