Skip to content

Instantly share code, notes, and snippets.

@taterbase
Created May 13, 2012 15:03
Show Gist options
  • Save taterbase/2688850 to your computer and use it in GitHub Desktop.
Save taterbase/2688850 to your computer and use it in GitHub Desktop.
Simple file upload in php
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
</form>
</body>
</html>
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
@TinySonhh
Copy link

Thank you,

@BawdyAnarchist
Copy link

Late to the party, but THANK YOU for putting a dead simple minimalist version of an upload. The only other guides I saw had all this extra crap that caused errors, required multiple files, etc.

This file just works. You might need to change your download folder, but it's simple and solid.

@sayantanHack
Copy link

Steps to Reproduce

For windows

  1. Run apache server or using Xampp run apache.
  2. Create an upload folder in C:\xampp\htdocs
  3. Also put this upload.php on the same folder C:\xampp\htdocs

For *Nix

  1. Create an upload folder in /var/www/html/
  2. Put the upload.php file in the same folder /var/www/html/
  3. Run Apache service.

@sensboston
Copy link

If someone needs similar (i.e. very simple) but a way more advanced and useful solution, please be my guest: https://github.com/sensboston/uploader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment