I am trying to remove spaces in the names of file uploads, but the below code does nothing.
<?php
session_start();
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db');
if(!isset($_SESSION['username']) && !isset($_SESSION['auth'])){
header('Location: /');
}
$username = $_SESSION['username'];
echo $username;
$dirs = mysql_query("SELECT * FROM `users` WHERE `usr_name` = '" . $username . "'") or die(mysql_error());
$r = mysql_fetch_assoc($dirs);
$dir = $r['usr_directory'];
if(isset($_FILES['upload'])){
$file_name = $_FILES['upload']['name'];
$file = preg_replace('/\s+/', '_', $file_name);
$_FILES['n'] = $file;
$current_time = date('n/j/Y ');
mysql_query("INSERT INTO `uploaded_files` (`username`,`file_name`,`time_updated`) VALUES('" . $username . "','" . $file . "','" . $current_time . "')") or die(mysql_error());
move_uploaded_file($_FILES['n']['tmp_name'], "usr_files/$dir/{$_FILES['upload']['name']}");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home - LAN File Upload</title>
</head>
<body>
<h1>Upload a file</h1>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="upload" id="file"><br />
<input type="submit" name="submit" value="Upload">
</form>
<b>Note: the larger the file, the longer it takes to upload.</b>
<h1>Account Settings</h1>
<b><a href="/file_browser.php">Your Files</a></b>
<b><a href="settings.php">Account Settings</a></b>
<b><a href="/?action=logout">Logout</a></b>
</body>
</html>
I don't know what is wrong with the code. It is supposed to remove the spaces in the names but does not upload the file to the server.