Skip to content

Instantly share code, notes, and snippets.

@maxixo
Created January 16, 2026 22:33
Show Gist options
  • Select an option

  • Save maxixo/36f304d46b1c177aca96708384dcb250 to your computer and use it in GitHub Desktop.

Select an option

Save maxixo/36f304d46b1c177aca96708384dcb250 to your computer and use it in GitHub Desktop.
How to upload files in PHP
<!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