abstract:<!--模板文件--> <?php include "config.php"; include "operation.php"; ?> <!doctype html> <html> <head> <meta&nbs
<!--模板文件--> <?php include "config.php"; include "operation.php"; ?> <!doctype html> <html> <head> <meta charset="UTF-8"> <title>PHP中文網(wǎng)—Web在線文件管理器</title> <link rel="stylesheet" href="css/cikonss.css"/> <link rel="stylesheet" href="css/style.css"/> <link rel="stylesheet" href="css/jquery-ui-1.10.4.custom.css" type="text/css"/> <script src="js/jquery-1.10.2.js"></script> <script src="js/jquery-ui-1.10.4.custom.js"></script> <script src="js/action.js"></script> </head> <body> <h1>PHP中文網(wǎng)—Web在線文件管理器</h1> <div id="showDetail" style="display:none"><img src="" id="showImg" alt=""/></div> <div id="top"> <ul id="navi"> <li><a href="index.php" title="主目錄"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span></span></span></a></li> <li><a href="#" onclick="show('createFile')" title="新建文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span ></span></span></a></li> <li><a href="#" onclick="show('createFolder')" title="新建文件夾"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span ></span></span></a></li> <li><a href="#" onclick="show('uploadFile')" title="上傳文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span ></span></span></a></li> <?php $back=$path=="file"?"file":dirname($path); ?> <li><a href="#" title="返回上級(jí)目錄" onclick="goBack('<?php echo $back;?>')"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span ></span></span></a></li> </ul> </div> <form action="index.php" method="post" enctype="multipart/form-data"> <table width="100%" border="1" cellpadding="5" cellspacing="0" bgcolor="#ABCDEF"> <tr id="createFolder" style="display:none;"> <td>請(qǐng)輸入文件夾名稱</td> <td> <input type="text" name="dirname"/> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="submit" name="act" value="創(chuàng)建文件夾"/> </td> </tr> <tr id="createFile" style="display:none;"> <td>請(qǐng)輸入文件名稱</td> <td> <input type="text" name="filename"/> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="submit" name="act" value="創(chuàng)建文件"/> </td> </tr> <tr id="uploadFile" style="display:none;"> <td>請(qǐng)選擇要上傳的文件</td> <td><input type="file" name="myFile"/> <input type="submit" name="act" value="上傳文件"/> </td> </tr> </table> </form> <table width="100%" border="1" cellpadding="5" cellspacing="0" bgcolor="#ABCDEF"> <tr> <th>編號(hào)</th> <th>名稱</th> <th>類型</th> <th>大小</th> <th>可讀</th> <th>可寫</th> <th>可執(zhí)行</th> <th>創(chuàng)建時(shí)間</th> <th>修改時(shí)間</th> <th>訪問時(shí)間</th> <th>操作</th> </tr> <?php if(@$data['file']){ $i = 1; foreach($data['file'] as $v){ $p = $path."/".$v; ?> <tr> <td><?php echo $i;?></td> <td><?php echo $v;?></td> <td><?php $src=filetype($p)=="file"?"file_ico.png":"folder_ico.png";?><img src="images/<?php echo $src;?>" title="文件"></td> <td><?php echo trans_byte(filesize($p))?></td> <td><?php $src=is_readable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php $src=is_writable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php $src=is_executable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php echo date("Y-m-d H:i:s",filectime($p));?></td> <td><?php echo date("Y-m-d H:i:s",filemtime($p));?></td> <td><?php echo date("Y-m-d H:i:s",fileatime($p));?></td> <td> <?php $ext = strtolower(pathinfo($v,PATHINFO_EXTENSION)); $imagesExt = ['gif','png','jpg','jpeg']; if(in_array($ext,$imagesExt)){ ?> <a href="#" onclick="showDetail('<?php echo $v?>','<?php echo $p;?>')"><img src="images/show.png" alt="" title="查看"/></a> <?php }else{ ?> <a href="index.php?act=showContent&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/show.png" alt="" title="查看"/></a> <?php } ?> <a href="index.php?act=editContent&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/edit.png" alt="" title="修改"/></a> <a href="index.php?act=renameFile&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/rename.png" alt="" title="重命名"/></a> <a href="index.php?act=copyFile&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/copy.png" alt="" title="復(fù)制"/></a> <a href="index.php?act=cutFile&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/cut.png" alt="" title="剪切"/></a> <a href="index.php?act=dowFile&path=<?php echo $path;?>&filename=<?php echo $p;?>"><img src="images/download.png" alt="" title="下載"/></a> <a href="#" onclick="delFile('<?php echo $p;?>','<?php echo $path;?>')"><img src="images/delete.png" alt="" title="刪除"/></a> </td> </tr> <?php $i++; } } if(@$data['dir']){ $i=1; foreach ($data['dir'] as $v){ $p=$path."/".$v; ?> <tr> <td><?php echo $i;?></td> <td><?php echo $v;?></td> <td><?php $src=filetype($p) =="dir"?"folder_ico.png":"file_ico.png";?><img src="images/<?php echo $src;?>" title="文件夾"></td> <td><?php $sum = 0; echo trans_byte(dir_size($p));?></td> <td><?php $src=is_readable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php $src=is_writable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php $src=is_executable($p)?"correct.png":"error.png";?><img src="images/<?php echo $src;?>"></td> <td><?php echo date("Y-m-d H:i:s",filectime($p));?></td> <td><?php echo date("Y-m-d H:i:s",filemtime($p));?></td> <td><?php echo date("Y-m-d H:i:s",fileatime($p));?></td> <td> <a href="index.php?path=<?php echo $p;?>"><img src="images/show.png" alt="" title="查看"/></a> <a href="index.php?act=renameFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>"><img src="images/rename.png" alt="" title="重命名"/></a> <a href="index.php?act=copyFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>"><img src="images/copy.png" alt="" title="復(fù)制"/></a> <a href="index.php?act=cutFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>"><img src="images/cut.png" alt="" title="剪切"/></a> <a href="#" onclick="delFolder('<?php echo $p;?>','<?php echo $path;?>')"><img src="images/delete.png" alt="" title="刪除"/></a> </td> </tr> <?php $i++; } } ?> </table> </body> </html>
<?php include "common.php"; if($act=="創(chuàng)建文件"){ $mes = create_file($path."/".$filename); alertMes($mes,$url); }elseif($act=="showContent"){ $content = read_file($filename); if(strlen($content)){ $newContent = highlight_string($content,true); $str=<<<HERE <table width="100%" bgcolor="#adff2f" cellpadding="5" cellspacing="0"> <tr> <td>{$newContent}</td> </tr> </table> HERE; echo $str; }else{ alertMes('文件為空!編輯后再查看',$url); } }elseif($act == "editContent"){ $content = file_get_contents($filename); $str=<<<HERE <form action = "index.php?act=doEdit" method="post"> <textarea cols="150" rows="10" name="content">{$content}</textarea> <input type="hidden" name="filename" value="{$filename}"> <input type="submit" value="修改內(nèi)容"> </form> HERE; echo $str; }elseif($act =="doEdit"){ $content=$_REQUEST['content']; if(file_put_contents($filename,$content)){ $mes='文件修改成功!'; }else{ $mes='文件修改失敗!'; } alertMes($mes,$url); }elseif($act == "renameFile"){ $str=<<<HERE <form action="index.php?act=doRename" method="post"> 輸入文件新名稱:<input type="text" name="newName" placeholder="請(qǐng)輸入新名稱"> <input type="hidden" name="path" value="{$path}"> <input type="hidden" name="filename" value="{$filename}"> <input type="submit" value="重命名"> </form> HERE; echo $str; }elseif($act=="doRename"){ $newName = $_REQUEST['newName']; $mes = rename_file($filename,$path."/".$newName); alertMes($mes,$url); }elseif($act=="copyFile"){ $str=<<<HERE <form action="index.php?act=coCopyFile" method="post"> 文件復(fù)制到:<input type="text" name="destName" placeholder="將文件復(fù)制到"> <input type="hidden" name="path" value="{$path}"> <input type="hidden" name="filename" value="{$filename}"> <input type="submit" value="復(fù)制文件"> </form> HERE; echo $str; }elseif($act == "coCopyFile"){ $destName=$_REQUEST['destName']; $mes=copy_file($filename,$path."/".$destName); alertMes($mes,$url); }elseif($act=="cutFile"){ $str=<<<HERE <form action="index.php?act=doCutFile" method="post"> 文件剪切到:<input type="text" name="destName" placeholder="將文件剪切到?"> <input type="hidden" name="path" value="{$path}"> <input type="hidden" name="filename" value="{$filename}"> <input type="submit" value="剪切文件"> </form> HERE; echo $str; }elseif($act=="doCutFile"){ $destName=$_REQUEST['destName']; $mes=cut_file($filename,$path."/".$destName); alertMes($mes,$url); }elseif($act=="dowFile"){ $mes=dow_file($filename); }elseif($act=="delFile"){ if(unlink($filename)){ alertMes("文件刪除成功!",$url); }else{ alertMes("文件刪除失?。?quot;,$url); } }elseif($act=="上傳文件"){ $fileInfo=$_FILES['myFile']; $mes=upload_file($fileInfo,$path); alertMes($mes,$url); }elseif($act=="創(chuàng)建文件夾"){ $mes=create_folder($path."/".$dirname); alertMes($mes,$url); }elseif($act=="renameFolder"){ $str=<<<HERE <form action="index.php?act=doRenameFolder" method="post"> 重命名為:<input type="text" name="newFolderName" placeholder="請(qǐng)輸入文件夾名稱"> <input type="hidden" name="dirname" value="{$dirname}"> <input type="hidden" name="path" value="{$path}"> <input type="submit" value="重命名"> </form> HERE; echo $str; }elseif($act=="doRenameFolder"){ $newFolderName = $_REQUEST['newFolderName']; $mes=rename_dir($dirname,$path."/".$newFolderName); alertMes($mes,$url); }elseif($act == "copyFolder"){ $str=<<<HERE <form action="index.php?act=doCopyFolder" method="post"> 復(fù)制為:<input type="text" name="newFolderName" placeholder="復(fù)制文件夾到"> <input type="hidden" name="dirname" value="{$dirname}"> <input type="hidden" name="path" value="{$path}"> <input type="submit" value="復(fù)制"> </form> HERE; echo $str; }elseif($act =="doCopyFolder"){ $newFolderName=$_REQUEST['newFolderName']; $mes=copy_dir($dirname,$path."/".$newFolderName."/".basename($dirname)); alertMes($mes,$url); }elseif($act=="cutFolder"){ $str=<<<HERE <form action="index.php?act=doCutFolder" method="post"> 剪切為:<input type="text" name="newFolderName" placeholder="剪切文件夾到"> <input type="hidden" name="dirname" value="{$dirname}"> <input type="hidden" name="path" value="{$path}"> <input type="submit" value="剪切"> </form> HERE; echo $str; }elseif($act=="doCutFolder"){ $newFolderName=$_REQUEST['newFolderName']; $mes=cut_dir($dirname,$path."/".$newFolderName); alertMes($mes,$url); }elseif($act=="delFolder"){ $mes=del_folder($dirname); alertMes($mes,$url); } ?>
<?php /** * 配置文件 */ include "function.php"; $path = "file"; @$path = $_REQUEST['path']?$_REQUEST['path']:$path; $data = read_dir($path); if(!$data){ echo "<script>alert('無(wú)文件或目錄!')</script>"; } @$act = $_REQUEST['act']; @$filename=$_REQUEST['filename']; @$dirname=$_REQUEST['dirname']; @$url = "index.php?path={$path}"; ?>
經(jīng)過本章節(jié)的多次重復(fù)練習(xí),雖然是跟著課堂案例來練?;緦?duì)php和html混編有初步的掌握。配置文件、和操作方法單獨(dú)管理。get、post 提交到接收的值處理,方法庫(kù)封裝的引用等知識(shí)。
Correcting teacher:查無(wú)此人Correction time:2019-05-06 09:42:56
Teacher's summary:完成的不錯(cuò)?;竟茉鷮?shí),以后對(duì)編寫項(xiàng)目有很大的幫助。繼續(xù)加油。