@daisha
To show the result after uploading a file in PHP, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 |
<!DOCTYPE html> <html> <head> <title>File Upload</title> </head> <body> <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file"> <input type="submit" value="Upload"> </form> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 |
<?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"]; } else { // Uploading process move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); // Show success message echo "File uploaded successfully!"; } ?> |
When a file is selected and the form is submitted, it will be sent to upload.php
using the POST method. In the PHP script, you can check if there were any errors during the file upload using $_FILES["file"]["error"]
. If there's an error, you can display the corresponding message. If the upload was successful, move the uploaded file to the desired location (in this example, "uploads" directory) using move_uploaded_file()
function and display a success message.