How can the use of the $_SERVER['PHP_SELF'] variable in file upload forms potentially lead to security vulnerabilities?

Using the $_SERVER['PHP_SELF'] variable in file upload forms can potentially lead to security vulnerabilities such as cross-site scripting attacks. To solve this issue, it is recommended to use htmlspecialchars() function to sanitize the input and prevent any malicious scripts from being injected.

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>