How can a contact form with image upload functionality be integrated into a static HTML page using PHP?
To integrate a contact form with image upload functionality into a static HTML page using PHP, you can create a PHP script that handles the form submission and processes the uploaded image. You will need to use the enctype attribute in the form tag to allow file uploads. The PHP script should move the uploaded image to a specified directory on the server and store the file path in a database or send it via email.
```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["image"]["name"]);
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
// Image uploaded successfully, handle the rest of the form submission
// For example, store the file path in a database or send it via email
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
```
This code snippet checks if the form has been submitted using the POST method, retrieves the form data, and moves the uploaded image to the specified directory. You can then process the form data and the file path as needed.