What potential issue is highlighted in the provided PHP code for a file upload system?
The potential issue in the provided PHP code is the lack of validation on the uploaded file type. This can lead to security vulnerabilities such as allowing users to upload malicious files. To solve this issue, you should implement file type validation to only allow specific file types to be uploaded.
// Validate file type before uploading
$allowedFileTypes = ['jpg', 'jpeg', 'png', 'gif'];
$uploadedFileType = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION);
if (!in_array($uploadedFileType, $allowedFileTypes)) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
} else {
// Upload file logic here
}