新建文件夹所用PHP函数 mkdir(文件夹名,权限值一般是0777)
存入文件所用PHP函数 fopen()函数详细参考下PHP手册,看文件操作库

解决方案 »

  1.   

    <?
    //设置路径(默认当前php文件所在路径)
    $basedir = "c:/inetpub/";
    $textrows = "20";
    $textcols = "85";
    if(!$wdir) $wdir="/";
    //HTML的标头
    function html_header(){
    global $basedir;
    global $wdir;
    global $lastaction;
    echo "<HEAD>";
    echo "<TITLE>文件目录操作</TITLE>";
    echo "</HEAD>";
    echo "<BODY bgcolor=\"#fafad2\" link=\"#4C4C99\" vlink=\"#4C4C99\" alink=\"#4C4C99\">";
    echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"600\">";
    echo "<tr>";
    echo "<th colspan=\"2\" width=\"100%\" bgcolor=\"#00bfff\">";
    echo "&nbsp;<font size=\"6\" color=\"white\" face=\"arial, helvetica\">文件操作系统</font> &nbsp";
    echo "</th>";
    echo "</tr>";
    echo "<tr>";
    echo "<td width\"50%\" align=\"left\"><A HREF=\"$PHP_SELF?action=root\"><font size=\"4\" face=\"arial, helvetica\">回根目录($basedir)</font></a></td>";
    echo "<td width\"50%\" align=\"right\"><A HREF=\"$PHP_SELF?wdir=$wdir\" title=\"Refresh current dir\"><font size=\"4\" face=\"arial, helvetica\">$wdir</font><img src=\"explore.gif\" border=\"0\"></a></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan=\"2\"><hr></td>";
    echo "</tr>";
    echo "<tr>";
    echo " <td colspan=\"2\"><b><font size=\"3\" color=\"#4C4C99\" face=\"arial, helvetica\">$lastaction</font></b></td>";
    echo "<tr>";
    echo "<td colspan=\"2\"><hr><td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan=\"2\">";
    }
    //计算文件大小
    function display_size($file){
    $file_size = filesize($file);
    if($file_size >= 1073741824)
      {
            $file_size = round($file_size / 1073741824 * 100) / 100 . "g";
    }
    elseif($file_size >= 1048576)
    {
            $file_size = round($file_size / 1048576 * 100) / 100 . "m";
    }
    elseif($file_size >= 1024)
    {
            $file_size = round($file_size / 1024 * 100) / 100 . "k";
    }
    else{
            $file_size = $file_size . "b";
    }
    return $file_size;
    }
    //文件列表函数 
    function displaydir()
    {
    global $basedir;
    global $wdir;
    //Table标题
    echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";
    echo "<tr>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">类型</font></th>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">名称</font></th>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">大小</font></th>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">修改时间</font></th>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">属性</font></th>";
    echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">操作</font></th>";
    echo "</tr>";
    //将子目录和文件存放在数组中
    //echo $basedir . $wdir;
    chdir($basedir . $wdir);
    $handle=opendir(".");
    while ($file = readdir($handle))
    {
    if(is_dir($file)) $dirlist[] = $file;
    if(is_file($file)) $filelist[] = $file;
    }
    closedir($handle);
    //首先存放子目录
      

  2.   


    if($dirlist)
    {
    //目录排序
    asort($dirlist);
    //遍厉数组
    while (list ($key, $file) = each ($dirlist))
    {
    //
    if (!($file == "."))
    {
    $filename=$basedir.$wdir.$file;
    $fileurl=rawurlencode($wdir.$file);
    $lastchanged = filectime($filename);
    $changeddate = date("d-m-Y H:i:s", $lastchanged);
    echo "<TR>"; //建立回上一级目录的箭头
    if($file == "..")
    {
    $downdir = dirname("$wdir");
    echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Parent directory\" border=\"0\"></a></TD>\n";
    echo "<TD></TD>\n";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
    printf("%o", (fileperms($filename)) & 0777);
    echo "</TD><TD nobreak>";
    echo "<A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Parent directory\" border=\"0\"></A> ";
    }
     //列出目录
     else
    {
    $lastchanged = filectime($filename);
    echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\"><img src=\"folder.gif\" alt=\"$basedir$file\" border=\"0\"></a></TD>\n";
    echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
    echo "<A HREF=\"$PHP_SELF?action=chmod&file=$filename\"><font size =\"-1\" face=\"arial, helvetica\">";
    printf("%o", (fileperms($filename)) & 0777);
    echo "</A>";
    echo "</font></TD><TD nobreak>";
    echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\"></A> ";
    echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"></A> ";
    echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"delete.gif\" alt=\"Delete $file\" border=\"0\"></A> ";
    }
    }
    }
    }
    //列出文件
    if($filelist)
    {
    //文件排序
    asort($filelist);
    while (list ($key, $file) = each ($filelist))
    {
    //检查文件格式并显示相应的图表和属性
    //图片文件
    if (ereg(".gif|.jpg",$file))
    {
    $icon = "<IMG SRC=\"image.gif\" alt=\"Image\" border=\"0\">";
    $browse = "1";
    $raw = "0";
    $image = "1";
    }
    //文本文件
    elseif (ereg(".txt",$file))
    {
    $icon = "<IMG SRC=\"text.gif\" alt=\"Text\" border=\"0\">";
    $browse = "1";
    $raw = "1";
    $image = "0";
    }
    //音频文件
    elseif (ereg(".wav|.mp2|.mp3|.mp4|.vqf|.midi",$file))
    {
    $icon = "<IMG SRC=\"audio.gif\" alt=\"Audio\" border=\"0\">";
    $browse = "1";
    $raw = "0";
    $image = "0";
    }
    //Web服务器文件
    elseif (ereg(".phps|.php|.php2|.php3|.php4|.asp|.asa|.cgi|.pl|.shtml",$file)) 
    {
    $icon = "<IMG SRC=\"webscript.gif\" alt=\"Web program\" border=\"0\">";
    $browse = "1";
    $raw = "1";
    $image = "0";
    }
    //Apache Web服务器安全设置
    elseif (ereg(".htaccess",$file))
    {
    $icon = "<IMG SRC=\"security.gif\" alt=\"Apache Webserver security settings\" border=\"0\">" ;
    $browse = "0";
    $raw = "1";
    $image = "0";
    }
    //Web页面文件
    elseif (ereg(".html|.htm",$file))
    {
    $icon = "<IMG SRC=\"webpage.gif\" alt=\"Web page\" border=\"0\">";
    $browse = "1";
    $raw = "1";
    $image = "0";
    }
    //不确定格式文件
      

  3.   


    else

    $icon = "<IMG SRC=\"text.gif\" alt=\"Unknown filetype\" border=\"0\">";
    $browse = "1";
    $raw = "1";
    $image = "0";
    }
    //文件列表
    $filename=$basedir.$wdir.$file;
    $fileurl=rawurlencode($wdir.$file);
    $lastchanged = filectime($filename);
    $changeddate = date("d-m-Y H:i:s", $lastchanged);
    echo "<TR>";
    echo "<TD align=\"center\" nobreak>";
    //产生文件图标以便预览
    if($raw == "1")
    {
    echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\">";
    }
    if($image == "1")
    {
    echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\">";
    }
    echo "$icon</TD>\n";
    echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
    echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
    echo "<A HREF=\"$PHP_SELF?action=chmod&wdir=$wdir&file=$fileurl\" title=\"Change permission level on $file\"><font size =\"-1\" face=\"arial, helvetica\">";
    printf("%o", (fileperms($filename)) & 0777);
    echo "</font></A>";
    echo "</TD><TD nobreak>";
    echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\"></A> ";
    echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"></A> ";
    echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"delete.gif\" alt=\"Delete $file\" border=\"0\"></A> ";
    //如果文件可以浏览,则给出浏览图标 
    if($browse == "1")
    {
    echo " <A HREF=\"$wdir$file\"><img src=\"browse.gif\" alt=\"Browse\" border=\"0\"></A> ";
    }
    //如果文件可以编辑,则给出编辑图标 
    if($raw =="1")
    {
    echo " <A HREF=\"$PHP_SELF?wdir=$wdir&action=edit&file=$fileurl\"><img src=\"edit.gif\" alt=\"Edit\" border=\"0\"></A> ";
    }
    }
    }
    echo "</TD></TR>\n";
    echo "</TABLE>";
    //显示出不同提交的Form表
    echo "<table border=\"0\" width=\"100%\">";
    echo "<TR><TD colspan=\"2\"><hr></td>";
    //文件上传
    echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">上传文件</font></td><td>";
    echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
    echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
    echo "<INPUT NAME=\"userfile\" TYPE=\"file\" size=\"40\">";
    echo "<INPUT TYPE=\"SUBMIT\" NAME=\"upload\" VALUE=\"Go!\"></TD></TR>";
    echo "</FORM>";
    //创建新目录
    echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
    echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">创建目录</font></td><td>";
    echo "<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">";
    echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"mkdir\">";
    echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
    echo "<INPUT TYPE=\"SUBMIT\" NAME=\"mkdir\"  VALUE=\"Go!\"></TD></TR>";
    echo "</FORM>";
    //产生新文件
    echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
    echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">新建文件</font></td><td>";
    echo "<INPUT TYPE=\"TEXT\" NAME=\"file\" size=\"40\">";
    echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\"> ";
    echo "<input type=\"checkbox\" name=\"html\" value=\"yes\"><font size =\"-2\" face=\"arial, helvetica\">(html template)</font> ";
    echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
    echo "<INPUT TYPE=\"SUBMIT\" NAME=\"createfile\" VALUE=\"Go!\">";
    echo "</TD></TR>";
    echo "</TABLE>";
    echo "</FORM>";
    }
    //用户点击CANCEL,取消提交
    if($cancel) $action="";
    //上传文件处理
    if($upload) 
    {
    copy($userfile,$basedir.$wdir.$userfile_name); 
    $lastaction = "上传文件到 $basedir$wdir";
    html_header();
    displaydir();
    echo $html_ender;
    exit;
    }
    ################################################################################
    //开始处理actions
    switch ($action)
    {
    //没有$action变量则显示初始页面
    case "":
    $lastaction = "$basedir";
    html_header();
    displaydir();
    echo $html_ender;
    break;
    //回根目录
    case "root":
        $wdir="/";
    $lastaction = "$basedir";
    html_header();
    displaydir();
    echo $html_ender;
    break;
    //改变目录
    case "chdr":
    $wdir=$file."/";
    $lastaction = "$basedir$wdir";
    html_header();
    displaydir();
    echo $html_ender;
    break;
    // 改动的对象
    case "touch":
    touch($basedir.$touchfile);
    $lastaction = "Touched $touchfile";
    html_header();
    displaydir();
    echo $html_ender;
    break;
    //调试报表
    case "bugreport":
    if ($send)
    {
      $lastaction = "Bug reported. Thank you!";
    html_header();
    mail("[email protected]","Bug report","Name: $name \nVersion: $version \n\nProblem: $problem");
    echo "<h3><a href=\"$PHP_SELF?action=help&wdir=$wdir\">Back to help</a></h3>";
    }
    else
    {
    $lastaction = "Bug report form";
    html_header();
    ?>
    <table>
    <form action="<? echo "$PHP_SELF?action=bugreport&wdir=$wdir&send=1"; ?>" method="POST">
    <tr>
    <td>Your name:</td>
    <td><input name="name" size="24" maxlength="30"></td>
    </tr><tr>
    <td>Your email adress:</td>
    <td><input name="email" size="24" maxlength="30"></td>
    </tr><tr>
    <td>Description of problem(s):</td>
    <td><textarea name="problem" cols="30" rows="5"></textarea></td>
    </tr><tr>
    <td colspan="2" align="center"><input type="submit" value="Send"></td>
    </tr>
    </table>
    <?
    }
    echo $html_ender;
    break;
    //删除文件或目录