Skip to content

Instantly share code, notes, and snippets.

@martiner
Created November 22, 2012 19:31
Show Gist options
  • Save martiner/4132631 to your computer and use it in GitHub Desktop.
Save martiner/4132631 to your computer and use it in GitHub Desktop.
PHP upload
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Filename: <input type="file" name="file"></label>
<input type="submit" value="Submit">
</form>
<?php
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else if ($_FILES["file"]["name"]) {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment