What potential issues or errors can occur when using this upload script?
One potential issue that can occur when using this upload script is that it does not check for file type before allowing the upload. This can lead to security vulnerabilities if users are able to upload malicious files. To solve this issue, we can add a check to ensure that only specific file types are allowed for upload.
// Check file type before allowing upload
$allowedFileTypes = ['jpg', 'jpeg', 'png', 'gif'];
$uploadedFileType = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
if (!in_array($uploadedFileType, $allowedFileTypes)) {
echo "Only JPG, JPEG, PNG, and GIF files are allowed for upload.";
exit;
}