Webmaster общности: Predpriemach.com | SearchEngines.bg

    File Manager

    Може да качвате файлове да ги едитвате и да ги триете.

    Структура:

    control
    /control/file.php
    /control/open.php
    /control/edit.php
    /control/del.php
    /control/style.css
    /control/edit.gif
    /control/del.gif
    project
    /project/.htaccess
    /project/file/

    file.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>File Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
    <?
    /************************************************************
    * File Manager Dir
    ************************************************************/
    
    $current_dir = ("../project/file/");
    
    /************************************************************/
    echo ("<table class=\"table\" align=\"center\"><tr><td align=\"center\" colspan=\"4\" class=\"fm\"><b>File Manager</b></td></tr><tr><td colspan=\"4\" class=\"up\" align=\"center\"><br /><form name=\"form\" enctype=\"multipart/form-data\" method=\"post\" action=\"file.php\"><input type=\"file\" name=\"file\"><input name=\"Send\" type=\"submit\" value=\"Upload\"></form>");
    if (is_uploaded_file($HTTP_POST_FILES['file']['tmp_name']))
    {
    $upload_dir = $current_dir;
    $upname = $_FILES['file']['name'];
    $upname = str_replace(" ","",$upname);
    $uptype = $_FILES['file']['type'];
    $upsize = $_FILES['file']['size'];
    if ( $uptype == 'image/jpeg' || $uptype == 'image/gif' || $uptype == 'text/html' || $uptype == 'text/plain'|| $uptype == 'text/css' || $uptype == 'application/x-javascript' || $uptype == 'audio/x-pn-realaudio-plugin' || $uptype == 'application/x-zip' )
    {
    echo ("<div class=\"u\">Успешно качихте файл <b>$upname</b> ($uptype)</div>");
    }
    else
    {
    echo ("<div class=\"z\">Файла не може да бъде качен <b>$upname</b> ($uptype)</div><br /><div class=\"u\">Може да качвате само jpeg, gif, html, txt, css, js, zip и rar.</div><br /><br />");
    echo ("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=file.php\">");
    exit;
    }
    if(($upsize < 6250000) && ($upsize!=0))
    {
    $upname=strtolower($upname);
    copy($file,$upload_dir.$upname);
    }
    else
    {
    echo ("<div class=\"z\">Файла е по голям от 5 MB</div>");
    }
    }
    echo ("</td></tr>");
    echo ("<tr><td class=\"td\" align=\"center\"><b>Файл</b></td><td class=\"td2\" align=\"center\"><b>Размер</b></td><td class=\"td3\" align=\"center\"><b>Едит</b></td><td class=\"td3\" align=\"center\"><b>Изтрий</b></td></tr>");
    $dir = opendir($current_dir);
    while ($files = readdir($dir))
    {
    $file_array[] = $files;
    }
    foreach ($file_array as $files)
    {
    echo "";
    if($files == ".." || $files == ".")
    {
    continue;
    }
    echo ("<tr class=\"b\">");
    echo ("<td class=\"file\">");
    echo ("<a href=\"$current_dir$files\" target=\"_blank\">$files</a>");
    echo ("</td><td class=\"size\">");
    $file = $current_dir.$files;
    $sizef = filesize($file);
    $i=0;
    $iec = array( " Bytes", " KB", " MB", " GB");
    while (($sizef/1024)>1)
    {
    $sizef=$sizef/1024;
    $i++;
    }
    echo substr($sizef,0,strpos($sizef,'.')+4).$iec[$i];
    echo ("</td><td align=\"center\" class=\"del\">");
    echo ("<a href=\"open.php?edit=$files\"><img src=\"edit.gif\" border=\"0\" alt=\"edit\"></a>");
    echo ("</td><td align=\"center\" class=\"del\">");
    echo ("<a href=\"del.php?target=$files\"><img src=\"del.gif\" border=\"0\" alt=\"del\"></a>");
    echo ("</td>");
    echo ("</tr>");
    }
    closedir($dir);
    echo ("<tr><td align=\"right\" class=\"papka\">Общия размер на директорията е</td>
    <td class=\"razmer\">");
    function dirusage($directory)
    {
    if (!is_dir($directory))
    {
    echo ("Директорията не съществува!");
    }
    $size = 0;
    if ($dir = opendir($directory))
    {
    while (($dirfile = readdir($dir)) !== false)
    {
    $path = $directory.'/'.$dirfile;
    if (is_link($path) || $dirfile == '.' || $dirfile == '..')
    {
    continue;
    }
    if (is_file($path))
    {
    $size += filesize($path);
    }
    if (is_dir($path))
    {
    $dirSize = dirusage($path);
    if ($dirSize >= 0)
    {
    $size += $dirSize;
    }
    else
    {
    return false;
    }
    }
    }
    closedir($dir);
    return $size;
    }
    }
    $size = dirusage($current_dir);
    if($size >= 1073741824)
    {
    $size = round($size / 1073741824 * 100) / 100 . " GB";
    }
    elseif($size >= 1048576)
    {
    $size = round($size / 1048576 * 100) / 100 . " MB";
    }
    elseif($size >= 1024)
    {
    $size = round($size / 1024 * 100) / 100 . " KB";
    }
    else
    {
    $size = $size . " B";
    }
    echo ("<b>$size</b>");
    echo ("</td>");
    echo ("<td class=\"pole\"></td>");
    echo ("<td class=\"pole2\"></td>");
    echo ("</tr>");
    echo ("</table>");
    ?>
    </body>
    </html>

    open.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>File Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
    <table class="table" align="center">
    <tr><td align="center" colspan="4" class="fm"><b>File Manager</b></td></tr>
    <tr><td colspan="4" class="up" align="center"><br />
    <?
    echo ("<div class=\"r\">Редактиране на файл <b>$edit</b>") ?>
    <br /><br /></td></tr>
    <tr><td class="td" align="center"><b>Съдържание:</b></td></tr><tr><td class="file">
    <?php
    /************************************************************
    * File Manager Dir
    ************************************************************/
    
    $current_dir = ("../project/file/");
    
    /************************************************************/
    $fp = fopen ($current_dir.$_GET['edit'],"r");
    $file= fread ($fp, filesize ($current_dir.$_GET['edit']));
    $edit=$_GET['edit'];
    if (eregi('/',$edit)||$edit==''||$edit=='.'||$edit=='..')
    {
    exit;
    }
    echo ("
    <form method=\"post\" action=\"edit.php\" >
    <input name=\"faila\" type=\"hidden\" value=\"$edit\">
    <textarea name=\"write\" COLS=\"80\" ROWS=\"30\">");
    echo $file;
    echo ("</textarea>
    <br /><center><INPUT TYPE=SUBMIT VALUE=\"Edit!\"></center>
    </form>");
    ?>
    </td></tr><tr>
    <td align="right" class="p" height="17"></td></tr>
    </table>
    </body>
    </html>

    edit.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>File Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    <link rel="stylesheet" href="style.css" type="text/css" />
    <META HTTP-EQUIV="Refresh" CONTENT="0; URL=file.php">
    </head>
    <body>
    <?php
    /************************************************************
    * File Manager Dir
    ************************************************************/
    
    $current_dir = ("../project/file/");
    
    /************************************************************/
    $thetext = $_POST['write'];
    $posta = $_POST['faila'];
    $editva = $current_dir.$posta;
    $fp = fopen ($editva,"w");
    $text = stripslashes($thetext);
    fwrite($fp, $text );
    fclose($fp);
    ?>
    </body>
    </html>

    del.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>File Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    <link rel="stylesheet" href="style.css" type="text/css" />
    <META HTTP-EQUIV="Refresh" CONTENT="1; URL=file.php">
    </head>
    <body>
    <?php
    /************************************************************
    * File Manager Dir
    ************************************************************/
    
    $current_dir = ("../project/file/");
    
    /************************************************************/
    $_GET['target'] = preg_replace('#(\\\|/)#', '', $_GET['target']);
    $del = $_GET['target'];
    if (eregi('/',$del)||$del==''||$del=='.'||$del=='..')
    {
    exit;
    }
    $filelocation = $current_dir.$_GET['target'];
    if (!unlink ($filelocation))
    {
    echo "<center>Файлът не може да бъде изтрит!</center>";
    }
    else
    {
    echo "<center>Файла беше изтрит успешно.</center>";
    exit;
    }
    ?>
    </body>
    </html>

    style.css

    body {
    background-color: #ffffff;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    }
    
    table.table {
    background: #D5EAF4;
    font-size: 12px;
    width: 511;
    border-collapse: collapse;
    border: solid #006699 1px;
    border: none;
    }
    td.fm {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    color: #24445B;
    background: #B1CCE0;
    font-size: 12px;
    }
    td.up {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    color: #24445B;
    background: #DCE9F1;
    font-size: 12px;
    }
    td.td {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    color: #24445B;
    background: #C0DCEC;
    font-size: 12px;
    }
    td.td2 {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    color: #24445B;
    background: #C0DCEC;
    font-size: 12px;
    }
    td.td3 {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    color: #24445B;
    background: #C0DCEC;
    font-size: 12px;
    }
    td.file {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    font-size: 11px;
    width: 350;
    }
    td.size {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #A3CEE7;
    font-size: 11px;
    color: #37698E;
    }
    td.del {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #7BB9DD;
    font-size: 12px;
    }
    td.papka {
    border: solid #006699 1px;
    border-right-width: 0px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #85AFCF;
    font-size: 12px;
    color: #E7EFF5;
    }
    td.razmer {
    border: solid #006699 1px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #85AFCF;
    font-size: 12px;
    color: #E7EFF5;
    text-align: center;
    }
    td.pole {
    border: solid #006699 1px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #85AFCF;
    font-size: 12px;
    }
    td.pole2 {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 0px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #85AFCF;
    font-size: 12px;
    }
    td.p {
    border: solid #006699 1px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-bottom-width: 1px;
    border-top-width: 1px;
    background: #85AFCF;
    font-size: 12px;
    color: #E7EFF5;
    }
    input.button {
    border-color: #94BAD6;
    background: #D1E1ED;
    font: 10px Verdana, Arial, Helvetica, sans-serif;
    border-width: 1px 1px 1px 1px;
    }
    input {
    border-color: #D1E1ED;
    color: #2B4157;
    font: normal 11px Verdana, Arial, Helvetica, sans-serif;
    border-width: 1px 1px 1px 1px;
    border: 1px solid #94BAD6;
    background-color: #EDF3F8;
    }
    div.u {
    color: #009966;
    font-size: 10px;
    }
    div.z {
    color: #FF0000;
    font-size: 10px;
    }
    div.r {
    font-size: 12px;
    }
    tr.b:hover {background:#E7EFF5
    }
    textarea {
    border-color: #B3CDE1;
    color: #2B4157;
    font: normal 11px Verdana, Arial, Helvetica, sans-serif;
    border-width: 1px 1px 1px 1px;
    border: 1px solid #94BAD6;
    background-color: #EDF3F8;
    }
    a {
    text-decoration: none;color: #6633CC;
    }
    a:hover {
    text-decoration: none;color: #8080FF;
    }

    .htaccess

    <Files "*.php">
    Order allow,deny
    Deny from all
    </Files>
    AddHandler text/html .php .php3 .php4 .php5 .phtml .phps .pl .py .cgi
    

    Оставете коментар