How can HTML be integrated with PHP to display and save images simultaneously?
To display and save images simultaneously using HTML and PHP, you can create a form in HTML to upload the image file, then use PHP to process the file upload, save it to a directory on the server, and display it back to the user.
<?php
if(isset($_FILES['image'])){
$file_name = $_FILES['image']['name'];
$file_tmp = $_FILES['image']['tmp_name'];
move_uploaded_file($file_tmp, "images/".$file_name);
echo "Image uploaded successfully!<br>";
echo "<img src='images/".$file_name."' alt='uploaded image'>";
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="image" id="image">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
Keywords
Related Questions
- Are there any recommended libraries or tools for parsing and extracting data from HTML documents in PHP?
- In what ways can the PHP code for updating database records be improved for better readability and maintainability?
- How can the use of default parameter values in PHP functions enhance code clarity and efficiency?