62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
require 'php/classes/page.php';
|
|
require 'functions/func_filesystem.php';
|
|
require 'functions/func_file.php';
|
|
|
|
$page = new Page();
|
|
$user = $page->user();
|
|
|
|
# process a login if attempted
|
|
if(isset($_POST['username']) && isset($_POST['password']))
|
|
{
|
|
if(!$user->login($_POST['username'],$_POST['password']))
|
|
{
|
|
$page->addError('Username and/or password incorrect.');
|
|
}
|
|
}
|
|
# if a file is being uploaded
|
|
else if(isset($_FILES['doc_file']) && $user->exists())
|
|
{
|
|
# true flag allows this upload to overwrite any files with the same name
|
|
if($cleanName = file_process_upload('doc_file',$DOCROOT.'/uploads',true))
|
|
{
|
|
if(!chmod($DOCROOT.'/uploads/'.$cleanName,0777))
|
|
$page->addError('Could not change permissions on file.');
|
|
$page->addMessage('File successfully uploaded.');
|
|
}
|
|
else
|
|
$page->addError('File upload failed.');
|
|
}
|
|
# if a file is being deleted
|
|
else if($_GET['do'] == 'delete' && $user->exists())
|
|
{
|
|
if(isset($_GET['id']) && file_exists($DOCROOT.'/uploads/'.$_GET['id']))
|
|
{
|
|
$fileName = file_sanitize_name($_GET['id']);
|
|
if(unlink($DOCROOT.'/uploads/'.$fileName))
|
|
$page->addMessage('File deleted.');
|
|
}
|
|
else
|
|
$page->addError('File does not exist. Deletion unsuccessful.');
|
|
}
|
|
# if a user already is present, then go to upload page
|
|
# otherwise go to login page
|
|
if($user->exists())
|
|
{
|
|
# get the list of files
|
|
$files = filesys_get_wanted_children($DOCROOT.'/uploads','folders',"/\.doc$/");
|
|
|
|
$page->data('files',$files);
|
|
$page->attr('title','Upload');
|
|
$page->content('home.php');
|
|
}
|
|
else
|
|
{
|
|
$page->display('menu',false);
|
|
$page->attr('title','Login');
|
|
$page->content('login.php');
|
|
}
|
|
|
|
$page->process();
|
|
|
|
?>
|