Can you provide an example of using the "!" operator with in_array in PHP for checking prohibited file extensions in an upload script?

When uploading files, it's important to validate the file extensions to prevent users from uploading potentially harmful files. One way to do this is by using the "!" operator with the in_array function in PHP. By checking if the file extension is not in an array of allowed extensions, we can identify and block prohibited file types from being uploaded.

$prohibitedExtensions = array("exe", "bat", "php"); // List of prohibited file extensions
$uploadedFile = "example.exe"; // Example uploaded file

$fileExtension = pathinfo($uploadedFile, PATHINFO_EXTENSION);

if (!in_array($fileExtension, $prohibitedExtensions)) {
    // File extension is not in the prohibited list, proceed with file upload
    echo "File uploaded successfully.";
} else {
    // Prohibited file extension detected, reject the file upload
    echo "Prohibited file type detected. File upload failed.";
}