What steps can be taken to debug and fix PHP code that is not functioning as expected when processing file uploads in a form?
When debugging PHP code that is not functioning as expected when processing file uploads in a form, ensure that the form has the correct enctype attribute set to "multipart/form-data". Additionally, check that the file upload size limit in php.ini is not exceeded and that the file upload directory has the correct permissions.
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
```
```php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
$uploadDir = 'uploads/';
$uploadFile = $uploadDir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
echo "File uploaded successfully.";
} else {
echo "Error uploading file.";
}
} else {
echo "Error uploading file: " . $_FILES['file']['error'];
}
}
?>