I am trying to write a script so that my users can have a web interface to upload files into their directory. I used a tutorial on file uploads, and for some reason the code doesn't seem to work. I end up with error code 0, which the PHP website says that the file uploaded successfully; however, it is not moving the file into the directory. Any ideas why?
<?
session_start();
//Send the user to the login page, if they aren't logged in
if(!$_SESSION['username']) {
echo "<center><font size='5' color='red'><b>PLEASE LOG IN</b></font></center>";
include('./includes/login_form.html');
exit();
}
//Grab the Session vars
foreach($_SESSION as $key => $value) {
$key = $value;
}
//Define Some Variables
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/fms/users/" . $username;
$upload_file = $upload_dir . $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file)) {
header("location:index2.php");
}
else {
echo "<center><font size='5' color='red'>An error occured!</font></center>";
echo "<pre>";
print_r($_FILES);
echo "</pre>";
}
?>