📄 qtofm.php4
字号:
<?php
/* QTOFileManager 1.0
*
*本程序经阿江汉化 阿江守候 http://www.ajiang.net
*
*Copyright (C) 2001 Quentin O'Sullivan <quentin@qto.com> All rights reserved.
*Web Site: http://www.qto.com/fm
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
************************************************************************
*/
// set these configuration variables
$user = ""; // 文件管理器使用权限用户名change this to the username you would like to use. leave it empty if you dont want to use authentication
$pass = "password"; //文件管理器使用权限密码
$MaxFileSize = "1000000"; // 最大文件限制(字节)max file size in bytes
$HDDSpace = "20000000"; // 网站最大空间 max total size of all files in directory
$HiddenFiles = array(".htaccess","COPYING","fileicon.gif","foldericon.gif","arrowicon.gif"); // 隐藏这些文件 add any file names to this array which should remain invisible
$EditOn = 1; // 如果不使用编辑功能则将这个参数设置为 0 make this = 0 if you dont want the to use the edit function at all
$EditExtensions = array("htm","html","txt","asp","php"); // 在这些文件类型后添加“编辑”连接 add the extensions of file types that you would like to be able to edit
$MakeDirOn = 1; // 如果不想要创建文件夹的功能,则将此参数设置为 0 make this = 0 if you dont want to be able to make directories
/********************************************************************/
$ThisFileName = basename(__FILE__); // get the file name
$path = str_replace($ThisFileName,"",__FILE__); // get the directory path
if($login)
{
if(!($u == $user && $password == $pass))
{
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>The login details were incorrect</font><br><br>";
$loginfailed = 1;
}
}
if($back)
{
$pathext = substr($pathext, 0, -1);
$slashpos = strrpos($pathext, "/");
if($slashpos == 0)
{
$pathext = "";
}
else
{
$pathext = substr($pathext, 0, ($slashpos+1));
}
}
if(($user == $u || $user == "") && $edit) // if an edit link was clicked
{
$fp = fopen($path.$pathext.$edit, "r");
$oldcontent = fread($fp, filesize($path.$pathext.$edit));
fclose($fp);
$filemanager = <<<content
<center>
<table border="0" cellspacing="0" cellpadding="20" bgcolor="#eeeeee">
<tr>
<td>
<font face="Arial, 宋体, Hevetica" size="4" color="#333333"><b>文件管理器</b></font><br>
<form name="form1" method="post" action="$PHP_SELF">
<center>
<textarea name="newcontent" cols="45" rows="15">$oldcontent</textarea>
<br>
<br>
<input type="submit" name="save" value="保存">
<input type="submit" name="cancel" value="重置">
<input type="hidden" name="u" value="$u">
<input type="hidden" name="savefile" value="$edit">
<input type="hidden" name="pathext" value="$pathext">
</center>
</form>
</td>
</tr>
</table>
</center>
content;
}
elseif(($user == $u || $user == "") && !$loginfailed)
{
if($save) // if the save button was pressed on the edit screen
{
$newcontent = stripslashes($newcontent);
$fp = fopen($path.$pathext.$savefile, "w");
fwrite($fp, $newcontent);
fclose($fp);
}
$HDDTotal = dirsize($path); // get the total size of all files in the directory including any sub directorys
if ($upload) // if the upload button was pressed
{
if($HTTP_POST_FILES['uploadedfile']['name']) // if a file was actually uploaded
{
$HTTP_POST_FILES['uploadedfile']['name'] = str_replace("%","",$HTTP_POST_FILES['uploadedfile']['name']); // remove any % signs from the file name
// if the file size is within allowed limits
if($HTTP_POST_FILES['uploadedfile']['size'] > 0 && $HTTP_POST_FILES['uploadedfile']['size'] < $MaxFileSize)
{
// if adding the file will not exceed the maximum allowed total
if(($HDDTotal + $HTTP_POST_FILES['uploadedfile']['size']) < $HDDSpace)
{
// put the file in the directory
move_uploaded_file($HTTP_POST_FILES['uploadedfile']['tmp_name'], $path.$pathext.$HTTP_POST_FILES['uploadedfile']['name']);
}
else
{
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>没有足够的空间来存放您要上传的文件。</font><br>";
}
}
else
{
$MaxKB = $MaxFileSize/1000; // show the max file size in Kb
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>正在上传的文件比限制的最大文件大,可上传的<br>最大文件是 $MaxKB Kb。</font><br>";
}
}
else
{
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>请点击“浏览...”按钮选择一个要上传的文件<br>然后再点击上传按钮.</font><br>";
}
}
elseif($delete) // if the delete button was pressed
{
// delete the file or directory
if(is_dir($path.$pathext.$delete))
{
$result = @rmdir($path.$pathext.$delete);
if($result == 0)
{
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>无法删除这个文件夹,必须是空文件夹才可以<br>被删除,或者您选错了文件夹。</font><br>";
}
}
else
{
unlink($path.$pathext.$delete);
}
}
elseif($mkdir && $MakeDirOn)
{
$result = @mkdir($path.$pathext.$dirname, 0700);
if($result == 0)
{
$msg = "<font face='Arial, 宋体, Hevetica' size='2' color='#ff0000'>无法创建这个文件夹,请检查你输入的文件<br>夹名字是否合法。</font><br>";
}
}
$HDDTotal = dirsize($path); // get the total size of all files in the directory including any sub directorys
$freespace = ($HDDSpace - $HDDTotal)/1000; // work out how much free space is left
$HDDTotal = (int) ($HDDTotal/1000); // convert to Kb instead of bytes and type cast it as an int
$freespace = (int) $freespace; // type cast as an int
$HDDSpace = (int) ($HDDSpace/1000); // convert to Kb instead of bytes and type cast it as an int
$MaxFileSizeKb = (int) ($MaxFileSize/1000); // convert to Kb instead of bytes and type cast it as an int
// if $MakeDirOn has been set to on show some html for making directories
if($MakeDirOn)
{
$mkdirhtml = "<input type=\"text\" name=\"dirname\" size=\"15\"><input type=\"submit\" name=\"mkdir\" value=\"创建文件夹\">";
}
// build the html that makes up the file manager
// the $filemanager variable holds the first part of the html
// including the form tags and the top 2 heading rows of the table which
// dont display files
$filemanager = <<<content
<center>
<table border='0' cellspacing='0' cellpadding='20' bgcolor='#eeeeee'>
<tr>
<td>
<font face="Arial, 宋体, Hevetica" size="4" color="#333333"><b>文件管理器</b></font><br>
$msg
<font face="Arial, 宋体, Hevetica" size="2"><b>总空间:</b> $HDDSpace Kb <b>最大文件:</b> $MaxFileSizeKb Kb</font><br>
<font face="Arial, 宋体, Hevetica" size="2"><b>剩余空间:</b> $freespace Kb <b>已用空间:</b> $HDDTotal Kb</font><br>
<form name="form1" method="post" action="$PHP_SELF" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="$MaxFileSize">
$mkdirhtml <br><input type="file" name="uploadedfile">
<input type="submit" name="upload" value="上传">
<input type="hidden" name="u" value="$u">
<input type="hidden" name="pathext" value="$pathext">
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="20" bgcolor="#333333"></td>
<td bgcolor="#333333" height="20"><font face="Arial, 宋体, Helvetica" size="2" color="#FFFFFF"><b> 文件名 </b></font></td>
<td height="20" bgcolor="#333333"><font color="#FFFFFF" size="2" face="Arial, 宋体, Helvetica"><b> 大小(字节) </b></font></td>
<td height="20" bgcolor="#333333"></td>
<td height="20" bgcolor="#333333"></td>
</tr>
<tr>
<td height="2" bgcolor="#999999"></td>
<td height="2" bgcolor="#999999"></td>
<td height="2" bgcolor="#999999"></td>
<td height="2" bgcolor="#999999"></td>
<td height="2" bgcolor="#999999"></td>
</tr>
content;
// if the current directory is a sub directory show a back link to get back to the previous directory
if($pathext)
{
$filemanager .= <<<content
<tr>
<td bgcolor="#ffffff"> <img src="arrowicon.gif"> </td>
<td> <a href="$PHP_SELF?u=$u&back=1&pathext=$pathext"><font face="Arial, 宋体, Helvetica" size="2" color="#666666">«上一层</font></a> </td>
<td bgcolor="#ffffff"></td>
<td></td>
<td bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
</tr>
content;
}
// build the table rows which contain the file information
$newpath = substr($path.$pathext, 0, -1); // remove the forward or backwards slash from the path
$dir = @opendir($newpath); // open the directory
while($file = readdir($dir)) // loop once for each name in the directory
{
// if the name is not a directory and the name is not the name of this program file
if($file != "." && $file != ".." && $file != "$ThisFileName")
{
$match = 0;
foreach($HiddenFiles as $name) // for each value in the hidden files array
{
if($file == $name) // check the name is not the same as the hidden file name
{
$match = 1; // set a flag if this name is supposed to be hidden
}
}
if(!$match) // if there were no matches the file should not be hidden
{
$filedata = stat($path.$pathext.$file); // get some info about the file
// find out if the file is one that can be edited
$editlink = "";
if($EditOn && !is_dir($path.$pathext.$file)) // if the edit function is turned on and the file is not a directory
{
$dotpos = strrpos($file, ".");
foreach($EditExtensions as $editext)
{
$ext = substr($file, ($dotpos+1));
if(strcmp($ext, $editext) == 0)
{
$editlink = " <a href='$PHP_SELF?edit=$file&u=$u&pathext=$pathext'><font face='Arial, 宋体, Helvetica' size='2' color='#666666'>编辑</font></a> ";
}
}
}
// create some html for a link to delete files
$deletelink = "<a href=\"$PHP_SELF?delete=$file&u=$u&pathext=$pathext\"><font face=\"Arial, 宋体, Helvetica\" size=\"2\" color=\"#666666\">删除</font></a>";
// if it is a directory change the file name to a directory link
if(is_dir($path.$pathext.$file))
{
$filename = "<a href=\"$PHP_SELF?u=$u&pathext=$pathext$file/\"><font color=\"#666666\">$file</font></a>";
$fileicon = " <img src=\"foldericon.gif\"> ";
if(!$MakeDirOn)
{
$deletelink = "";
}
}
else
{
$filename = $file;
$fileicon = " <img src=\"fileicon.gif\"> ";
}
// append 2 table rows to the $content variable, the first row has the file
// informtation, the 2nd row makes a black line 1 pixel high
$content .= <<<content
<tr>
<td bgcolor="#ffffff">$fileicon</td>
<td> <font face="Arial, 宋体, Helvetica" size="2">$filename</font> </td>
<td bgcolor="#ffffff"> <font face="Arial, 宋体, Helvetica" size="2">$filedata[7]</font> </td>
<td> $deletelink </td>
<td bgcolor="#ffffff">$editlink</td>
</tr>
<tr>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
<td height="1" bgcolor="#000000"></td>
</tr>
content;
}
}
}
closedir($dir); // now that all the rows have been built close the directory
$content .= "</td></tr></table></table></center>"; // add some closing tags to the $content variable
$filemanager .= $content; // append the html to the $filemanager variable
}
else
{
$filemanager = <<<content
<center>
<table border="0" cellspacing="0" cellpadding="20" bgcolor="#eeeeee">
<tr>
<td>
<font face="Arial, 宋体, Hevetica" size="4" color="#333333"><b>文件管理器</b></font><br>
<form name="form1" method="post" action="$PHP_SELF">
$msg
<center>
<font face="Arial, 宋体, Hevetica" size="2">用户名:</font><input type="text" name="u"><br>
<font face="Arial, 宋体, Hevetica" size="2">密 码:</font><input type="password" name="password"><br>
<input type="submit" name="login" value="登录">
</center>
</form>
</td>
</tr>
</table>
</center>
content;
}
function dirsize($dir)
// calculate the size of files in $dir
{
$dh = opendir($dir);
$size = 0;
while (($file = readdir($dh)) !== false)
{
if ($file != "." and $file != "..")
{
$path = $dir."/".$file;
if (is_dir($path))
{
$size += dirsize("$path/");
}
elseif (is_file($path))
{
$size += filesize($path);
}
}
}
closedir($dh);
return $size;
}
?>
<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<?php echo $filemanager ?>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -