Created
January 16, 2026 22:33
-
-
Save maxixo/36f304d46b1c177aca96708384dcb250 to your computer and use it in GitHub Desktop.
How to upload files in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>File Upload</title> | |
| </head> | |
| <body> | |
| <?php | |
| if(isset($_FILES['myFile'])) { | |
| $file = $_FILES['myFile']; | |
| $fileName = $file['name']; | |
| $tmpName = $file['tmp_name']; | |
| $fileSize = $file["size"]; | |
| $fileError = $file["error"]; | |
| if ($fileError === 0) { // Added $ here | |
| move_uploaded_file($tmpName, "uploads/" . $fileName); // Changed to $tmpName | |
| echo "file Uploaded sucessfully"; | |
| } else { | |
| echo "Upload failed with error code: $fileError"; | |
| } | |
| } | |
| ?> | |
| <br><br><br><br> | |
| <form action="upload.php" method="POST" enctype="multipart/form-data"> | |
| <label>Select file to upload</label> | |
| <input type="file" name="myFile"> | |
| <button type="submit">Upload</button> | |
| </form> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment