$path_one)
{
vt($path_array[$c]);
if ($path_array[$c] == '' && $c < count($path_array) - 1)
$path_array[$c] = '_';
}
$file = $path_array[count($path_array) - 1];
unset($path_array[count($path_array) - 1]);
if (count($path_array) > 0)
$path = implode('/', $path_array) . '/';
else
$path = '';
if (!is_dir("uploads/" . strtolower($login) . "/$path"))
mkdir("uploads/" . strtolower($login) . "/$path", 0777, true);
}
function listfiles_folder ($path)
{
global $login;
$fullpath = './uploads/' . strtolower($login) . $path;
$displayed = 0;
if ($handle = opendir($fullpath))
{
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
if (is_dir($fullpath . '/' . $file))
listfiles_folder($path . '/' . $file);
else
{
$displayed ++;
if ($displayed <= 5)
{
$f = $path . '/';
echo '';
}
}
}
}
closedir($handle);
}
}
function listfiles ()
{
echo '
';
}
function register ()
{
global $alert, $members;
if (isset($_POST['name']) && isset($_POST['password']) && isset($_POST['spamcheck']))
{
$name = $_POST['name'];
$password = $_POST['password'];
$spamcheck = $_POST['spamcheck'];
vt($name);
vt($password);
// spam check
if ($spamcheck != "Free Basic is great!")
{$alert = "You have failed the spam check!"; return;}
// validate name and password
if ($name == "" || $password == "")
{$alert = "The name or password is blank!"; return;}
for ($i = 0; $i < count($members); $i += 2)
{
if (strtolower($name) == strtolower($members[$i]))
{$alert = "This account has already been registered!"; return;}
}
// append member data to file and make folder
if (file_exists('data/members.dat'))
append('data/members.dat', ';' . $name . ';' . hash('sha384', $password));
else
{
file_put_contents('data/members.dat', $name . ';' . hash('sha384', $password));
chmod('data/members.dat', 0700);
}
mkdir('uploads/' . strtolower($name));
chmod('uploads/' . strtolower($name), 0777);
$alert = "Member $name is now registered!";
}
}
function login ()
{
global $alert, $refresh, $members;
if (isset($_POST['name']) && isset($_POST['password']))
{
$name = $_POST['name'];
$password = $_POST['password'];
vt($name);
vt($password);
if ($name == "")
{
if (isset($_COOKIE['name']) && $password == "")
{
setcookie('name');
setcookie('password');
$refresh = 'You have been logged out!';
}
else
$alert = "No name was entered!";
}
else
{
if ($password == "")
{
$alert = "No password was entered!";
return;
}
$cp = ""; // the password (must match the cookie); if blank, the user does not exist
// find member in list to see what his password should be
for ($i = 0; $i < count($members); $i += 2)
{
if (strtolower($name) == strtolower($members[$i]))
{$cp = $members[$i + 1];}
}
if ($cp == "")
{
$alert = "This member does not exist!";
return;
}
if (hash('sha384', $password) == $cp)
{
setcookie('name', $name, time() + 3600 * 24 * 3650);
setcookie('password', hash('sha384', $password), time() + 3600 * 24 * 3650);
$refresh = 'You are now logged in!';
return;
}
else
{
$alert = "This password is incorrect!";
return;
}
}
}
}
function paste ()
{
global $alert, $login;
if ($login == '')
{$alert = 'You are not logged in!'; return;}
if (!isset($_POST['paste']) || !isset($_POST['pastename']))
return;
// get paste
$paste = trim(stripslashes($_POST['paste']));
if ($paste == '')
{$alert = 'The paste is blank!'; return;}
// filename
$file = $_POST['pastename'];
setfilename($path, $file, $extension);
$filer = "uploads/" . strtolower($login) . "/$path$file.txt";
$download_destination = getcwd() . "/$filer";
// duplicates
if (file_exists($download_destination) && !isset($_POST['overwrite']))
{$alert = "The paste already exists!"; return;}
// save file
file_put_contents($download_destination, $paste);
append('data/files.dat', ";$filer");
$alert = "Pasted: $file [url]!';
}
function upload_file ($filenumber)
{
global $login;
if (!isset($_POST['filename' . $filenumber]) || !isset($_FILES['file' . $filenumber]))
return;
if ($_FILES['file' . $filenumber]['error'] == 4)
return;
$filename = $_POST['filename' . $filenumber];
setfilename($path, $filename, $fileextension);
if ($_FILES['file' . $filenumber]['error'] != 0)
return "Upload error #" . $_FILES['file' . $filenumber]['error'] . " has occured!";
$filer = "uploads/" . strtolower($login) . "/$path$filename$fileextension";
$download_destination = getcwd() . "/$filer";
if (file_exists($download_destination) && !isset($_POST['overwrite']))
return "The file already exists!";
if (move_uploaded_file($_FILES['file' . $filenumber]['tmp_name'], $download_destination))
{
chmod($download_destination, 0777);
if (file_exists('data/files.dat'))
append('data/files.dat', ";$filer");
else
{
file_put_contents('data/files.dat', $filer);
chmod('data/files.dat', 0700);
}
$r = "Uploaded: $filename [url]';
if ($fileextension == '.jpg' || $fileextension == '.png' || $fileextension == '.gif')
$r .= " [img]';
return $r . '!';
}
else
return "This file cannot be uploaded!";
}
function upload ()
{
global $alert, $login;
if ($login == '')
{$alert = 'You are not logged in!'; return;}
setcookie('lastpage', 'upload', time() + 3600 * 24 * 3650);
for ($i = 1; $i <= 3; $i ++)
{
$result = upload_file($i);
if ($result != '')
$alert .= "File #$i: $result
";
}
}
function manage ()
{
global $alert, $login;
if (isset($_POST['filename']))
{
if ($login == '')
{$alert = 'You are not logged in!'; return;}
$filename = $_POST['filename'];
setfilename($path, $filename, $extension);
$filename = "$path$filename$extension";
$fullfile = 'uploads/' . strtolower($login) . "/$filename";
if (is_dir('./' . $fullfile))
{$alert = $filename . ' cannot be deleted (is a directory)!'; return;}
if (!file_exists('./' . $fullfile))
{$alert = $filename . ' cannot be deleted (does not exist)!'; return;}
if (unlink('./' . $fullfile))
$alert = $filename . ' was deleted!';
else
$alert = $filename . ' cannot be deleted!';
}
}
function recentfiles ()
{
global $login;
// load file list
if (file_exists('data/files.dat'))
{
$c = file_get_contents('data/files.dat');
$files = explode(';', $c);
}
else
$c = array();
if ($login != '')
{
$displaytotal = 0;
echo '