<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
function print_form ()
{
echo "<p><h1>Enter file to upload</h1></p>";
echo "<form method='post' enctype='multipart/form-data'>";
echo "<input type='file' size='40' name='file1'><br>";
echo "Password: <input type='password' name='passwd'><br>";
echo "<input type=submit value='Upload!'>";
echo "</form>";
}
if (!$_FILES)
{
echo "<html><head><title>File Uploader</title></head>";
echo "<body>";
print_form ();
}
// Change password from 'secret' to 'somethingelse' here -------->|
elseif ($_POST['passwd'] != 'secret')
{
echo "<h1>Password Incorrect</h1>";
print_form ();
}
else{
$uploaddir = getcwd () . '/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file1']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['file1']['tmp_name'], $uploadfile)) {
echo "<h2>File is valid, and was successfully uploaded.</h2>";
} else {
echo "File Not Uploaded.";
}
}
?>