Hi
He is a very basic file manager, I don't feel like writing anything big, but this should do what you want!
follow these directions!
1. copy this code below into a text file and name it 'pass.php'
PHP Code:
<?php
// place the text login password you
// want to use for your login! ie: password
echo md5 ( 'place_your_password_here' );
?>
Now run that from your browser!
After running, copy the md5 hash to a text file....
example output!
1a3f91fead97497b1a96d6104ad339f6
Now copy the code below and place it in a new file called 'admin.php'
PHP Code:
<?
// do not touch, if you don't know what it does....
!isset($_COOKIE['sid']) && isset($_GET['sid']) && !empty($_GET['sid']) ? session_id($_GET['sid']) : (!isset($_COOKIE['sid']) ? session_id(md5(uniqid(microtime()))) : null);
session_name ( 'sid' );
session_start ();
define('UP_A', (!isset($_COOKIE['sid']) ? '?sid=' . session_id() : ''), true);
define('UP_B', (!isset($_COOKIE['sid']) ? '?sid=' . session_id() . '&' : '?'), true);
/*
*
* define the admin user
*
*/
define ( 'ADMIN_USER', 'admin' );
/*
*
* create a md5() password and place it in the define below!
* Use the script that is below this one to do this...
*
*/
define ( 'ADMIN_PASS', 'md5_pass_here' );
/*
*
* The upload folder path to the upload directory!
* On windows use full path (c:/www/docs/uploads/)
* !! INCLUDE TRAILING '/'
*
*/
define ( 'UPLOAD_PATH', 'e:/www/docs/www/docs/uploads/' );
// max number of files allowed to upload
define ( 'MAX_FILES', '5' );
// define the max single file size (bytes)
define ( 'MAX_SIZE', '1048576' );
// do not touch below....
$erro = array ();
if ( !empty ( $_REQUEST['logout'] ) && !empty ( $_SESSION['local']['in'] ) )
{
do_out ( '1' );
}
elseif ( !empty ( $_REQUEST['manage'] ) && !empty ( $_SESSION['local']['in'] ) )
{
run_manage ();
}
elseif ( !empty ( $_REQUEST['upload'] ) && !empty ( $_SESSION['local']['in'] ) )
{
upload_form ();
}
elseif ( !empty ( $_POST['login'] ) && test_login () )
{
upload_form ();
}
elseif ( empty ( $_SESSION['local']['in'] ) )
{
do_out ( '0' );
login_form ();
}
elseif ( !empty ( $_POST['send'] ) )
{
$return = array();
$x = 0;
for ( $i = 0; $i < sizeof ( $_FILES['up'] ); $i++ )
{
if ( is_uploaded_file ( $_FILES['up']['tmp_name'][$i] ) )
{
if ( $_FILES['up']['tmp_name'][$i] != 'none' )
{
$ss = filesize ( $_FILES['up']['tmp_name'][$i] );
if ( $ss > 10 && $ss <= MAX_SIZE )
{
$sn = $_FILES['up']['name'][$i];
if ( move_uploaded_file ( $_FILES['up']['tmp_name'][$i], UPLOAD_PATH . $sn ) )
{
$return[$x]['name'] = substr ( $sn, 0, strrpos ( $sn, '.' ) );
$return[$x]['type'] = substr ( $sn, ( strrpos ( $sn, '.' ) + 1 ) );
$return[$x]['size'] = $ss;
$x++;
}
}
}
}
}
process_return ( $return );
}
else
{
do_out ( '0' );
upload_form ();
}
function test_login ()
{
if ( ADMIN_USER == $_POST['admin'] && ADMIN_PASS == md5 ( $_POST['pass'] ) )
{
$_SESSION['local']['in'] = 1;
return ( 1 );
}
return ( 0 );
}
function do_out ( $type )
{
$_SESSION = array ();
session_destroy ();
if ( !empty ( $type ) )
{
header ( 'Location: ' . $_SERVER['PHP_SELF'] );
exit ();
}
}
function login_form ()
{
?>
<html>
<head>
<title>ADMIN UPLOAD LOGIN</title>
</head>
<body>
<center>
<form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>
<input type='hidden' name='login' value='1'>
<p></p>
<p></p>
USERNAME
<br />
<br />
<input type='text' name='admin' size='20' maxlength='20'>
<br />
<br />
PASSWORD
<br />
<br />
<input type='password' name='pass' size='20' maxlength='20'>
<br />
<br />
<input type='submit' name='submit' value='Login!'>
</form>
</center>
</body>
</html>
<?
exit ();
}
function upload_form ()
{
?>
<html>
<head>
<title>ADMIN UPLOAD FORM</title>
</head>
<body>
<center>
<br />
<br />
<a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>manage=1'>Manage Files</a> or <a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
<br />
<br />
<form enctype='multipart/form-data' action='<?=$_SERVER['PHP_SELF'];?><?=UP_A;?>' method='post'>
<input type='hidden' name='send' value='1'>
<p></p>
<p></p>
UPLOAD FILES
<br />
<br />
<?
for ( $i = 1; $i <= MAX_FILES; $i++ )
{
echo "<input type='file' name='up[]' size='40'>\r\n<br />\r\n";
}
?>
<br />
<br />
<input type='submit' name='submit' value='UPLOAD!'>
</form>
<center>
</body>
</html>
<?
exit ();
}
function process_return ( $in )
{
if ( !empty ( $in ) )
{
?>
<html>
<head>
<title>ADMIN UPLOAD RESULTS</title>
<style>
table {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
td {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
.zt, .mt {background-color: #ffffff;}
.st, .ft, .mh, .mi, .bttn {background-color: #777777;}
.st, .zt, .mh {border: 2px solid;}
.zt {border-color: #777777;}
.st {border-color: #000000;}
.mh, .bttn {border-color: #ffffff;}
.st, .mh, .mi, .bttn {color: #ffffff;}
.zt {padding: 6px;}
.st {padding: 4px;}
.mh, .mi {padding: 2px;}
.st, .zt, .mt, .ft, .mh, .mi, .bttn {font-size: 12px;}
.bttn {height: 21px;}
</style>
</head>
<body>
<center>
<table width='688'>
<tr>
<td class='zt' width='100%'>
<table width='672'>
<tr>
<td class='st'>FILES UPLOADED</td>
</tr>
<tr>
<td class='mt' width='100%' height='4'></td>
</tr>
<tr>
<td class='mt' width='100%' height='20'><a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
</tr>
<tr>
<td class='mt' width='100%' height='4'></td>
</tr>
<tr>
<td class='st'>
<table width='100%'>
<tr>
<td class='mh' width='4%' height='21'>#</td>
<td class='ft' width='2%'></td>
<td class='mh' width='52%' height='21'>FILE NAME</td>
<td class='ft' width='2%'></td>
<td class='mh' width='24%' height='21'>FILE SIZE</td>
<td class='ft' width='2%'></td>
<td class='mh' width='16%' height='21'>FILE TYPE</td>
</tr>
<?
for ( $i = 0; $i < sizeof ( $in ); $i++ )
{
$j = ( $i + 1 );
echo " <tr>
<td class='mi' width='4%' height='21'>" . ( $j < 10 ? '0' . $j : $j ) . "</td>
<td class='ft' width='2%'></td>
<td class='mi' width='52%' height='21'>" . $in[$i]['name'] . "</td>
<td class='ft' width='2%'></td>
<td class='mi' width='24%' height='21'>" . $in[$i]['size'] . " bytes</td>
<td class='ft' width='2%'></td>
<td class='mi' width='16%' height='21'>" . $in[$i]['type'] . "</td>
</tr>
";
}
?>
</table>
</td>
</tr>
<tr>
<td class='mt' width='100%' height='8'></td>
</tr>
<tr>
<td class='st'><input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1';" value='UPLOAD FILES'> <input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>manage=1';" value='MANAGE FILES'></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
<?
}
else
{
?>
<html>
<head>
<title>ADMIN UPLOAD ERROR</title>
<META HTTP-EQUIV="Refresh" Content="4;URL=<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1">
</head>
<body>
<center>
<p></p>
<p></p>
!! NO FILES BEING UPLOADED WERE VALID !!
<br />
<br />
redirecting you to the upload form...
<br />
<br />
<center>
</body>
</html>
<?
}
}
function run_manage ()
{
if ( !empty ( $_POST['delete'] ) )
{
do_delete ();
}
$files = get_files ();
if ( is_array ( $files ) && !empty ( $files ) )
{
?>
<html>
<head>
<title>ADMIN FILE MANAGE</title>
<style>
table {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
td {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
.zt, .mt {background-color: #ffffff;}
.st, .ft, .mh, .mi, .bttn {background-color: #777777;}
.st, .zt, .mh {border: 2px solid;}
.zt {border-color: #777777;}
.st {border-color: #000000;}
.mh, .bttn {border-color: #ffffff;}
.st, .mh, .mi, .bttn {color: #ffffff;}
.zt {padding: 6px;}
.st {padding: 4px;}
.mh, .mi {padding: 2px;}
.st, .zt, .mt, .ft, .mh, .mi, .bttn {font-size: 12px;}
.bttn {height: 21px;}
</style>
</head>
<body>
<center>
<table width='688'>
<form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>
<input type='hidden' name='manage' value='1'>
<tr>
<td class='zt' width='100%'>
<table width='672'>
<tr>
<td class='st'>CURRENT FILES LIST</td>
</tr>
<tr>
<td class='mt' width='100%' height='4'></td>
</tr>
<tr>
<td class='mt' width='100%' height='20'><a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
</tr>
<tr>
<td class='mt' width='100%' height='4'></td>
</tr>
<tr>
<td class='st'>
<table width='100%'>
<tr>
<td class='mh' width='4%' height='21'>#</td>
<td class='ft' width='2%'></td>
<td class='mh' width='44%' height='21'>FILE NAME</td>
<td class='ft' width='2%'></td>
<td class='mh' width='20%' height='21'>FILE SIZE</td>
<td class='ft' width='2%'></td>
<td class='mh' width='20%' height='21'>FILE DATE</td>
<td class='ft' width='2%'></td>
<td class='mh' width='4%' height='21'>DELETE</td>
</tr>
<?
for ( $i = 0; $i < sizeof ( $files ); $i++ )
{
$j = ( $i + 1 );
echo " <tr>
<td class='mi' width='4%' height='21'>" . ( $j < 10 ? '0' . $j : $j ) . "</td>
<td class='ft' width='2%'></td>
<td class='mi' width='44%' height='21'>" . $files[$i]['name'] . "</td>
<td class='ft' width='2%'></td>
<td class='mi' width='20%' height='21'>" . $files[$i]['size'] . " bytes</td>
<td class='ft' width='2%'></td>
<td class='mi' width='20%' height='21'>" . $files[$i]['date'] . "</td>
<td class='ft' width='2%'></td>
<td class='mh' width='4%' height='21'><input type='checkbox' name='delete[]' value='" . $files[$i]['file'] . "'></td>
</tr>
";
}
?>
</table>
</td>
</tr>
<tr>
<td class='mt' width='100%' height='8'></td>
</tr>
<tr>
<td class='st'><input type='submit' class='bttn' value='DELETE FILES'> <input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1';" value='UPLOAD FILES'></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
<?
}
else
{
?>
<html>
<head>
<title>ADMIN FILE MANAGER</title>
<META HTTP-EQUIV="Refresh" Content="4;URL=<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1">
</head>
<body>
<center>
<p></p>
<p></p>
!! THERE ARE NO FILES TO MANAGE !!
<br />
<br />
redirecting you to the upload form...
<br />
<br />
<center>
</body>
</html>
<?
}
}
function do_delete ()
{
foreach ( $_POST['delete'] as $file )
{
$now = UPLOAD_PATH . pack ( "H*", $file );
if ( file_exists ( $now ) )
{
unlink ( $now );
}
}
}
function get_files ()
{
$out = array ();
$x = 0;
if ( is_dir ( UPLOAD_PATH ) )
{
$td = opendir ( UPLOAD_PATH );
while ( false !== ( $file = readdir ( $td ) ) )
{
if ( $file != '.' && $file != '..' && !is_dir ( UPLOAD_PATH . $file ) )
{
$out[$x]['name'] = $file;
$out[$x]['size'] = filesize ( UPLOAD_PATH . $file );
$out[$x]['date'] = date ( 'F d Y H:i:s', filemtime ( UPLOAD_PATH . $file ) );
$out[$x]['file'] = bin2hex ( $file );
$x++;
}
}
closedir ( $td );
clearstatcache ();
}
return ( $out );
}
?>
Ok now lets configure the script 'admin.php'
in 'admin.php' find this line....
Code:
define ( 'ADMIN_USER', 'admin' );
change 'admin' to the name you want to login with
next find this line
Code:
define ( 'ADMIN_PASS', 'md5_pass_here' );
change 'md5_pass_here' to the md5 hash you created using the 'pass.php' script above!
next find this line
Code:
define ( 'UPLOAD_PATH', 'e:/www/docs/uploads/' );
change 'e:/www/docs/uploads/' to the full path where the uploaded files will be placed! (NOTE: be sure to include the trailing '/') on windows use full path, including the drive letter and forward slashes '/' like my example! If your on Unix/Linux you should know what to do!
next find this line
Code:
define ( 'MAX_FILES', '5' );
change '5' to the total amount of files that are allowed to be uploaded at one time!
next find this line
Code:
define ( 'MAX_SIZE', '1048576' );
change '1048576' in total Bytes for the max file size for any single file upload!
After save changes and place the script anywhere in your web root and call it from your browser to login!
The script allows for uploading, veiwing and deleting files in the upload directory! It uses sessions FILE based cookie or url passed! Like I said a very simple manager, but comes in handy at times! You could extend it so you can manage any directory by just making that a simple option in the veiw files manager
!J
Bookmarks