DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Very Simple Php File Upload
I think this is the minimum necessary to upload a file in php. First, the form, index.php:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
Next, the php to accept the file, upload.php
<?php
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>






Comments
Abagaw Gagaf replied on Tue, 2013/04/23 - 6:03am
another solution may be posted on stackoverflow - php simple file upload script
Anush Anil Kumar replied on Fri, 2012/09/07 - 3:57pm
Snippets Manager replied on Tue, 2011/02/01 - 8:33pm
Snippets Manager replied on Tue, 2007/06/05 - 11:43am
Roger Douglass replied on Sat, 2007/04/21 - 12:35pm