ホームページ >php教程 >php手册 >PHPファイル閲覧機能

PHPファイル閲覧機能

WBOY
WBOYオリジナル
2016-06-21 08:52:40852ブラウズ

PHP文件浏览功能,如下代码:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span>文件浏览</span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> </span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><</span><span class="tag-name">style</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span class="tag">></span><span> </span></span></li>
<li>
<span><!-- </span></li><li class="alt"><span>a:link {text-decoration: none;} </span></li><li><span>a:visited {text-decoration: none;} </span></li><li class="alt"><span>a:hover {text-decoration: none;} </span></li><li><span>a:active {text-decoration: none;} </span></li><li class="alt"><span>.style1 {font-size: 12px} </span></li><li><span>--<span class="tag">></span><span> </span>
</li>
<li class="alt"><span><span class="tag"></</span><span class="tag-name">style</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">h3</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span>文件浏览 - www.cxybl.com</span><span class="tag"></</span><span class="tag-name">h3</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span> </span></span></li>
<li><span>    <span class="tag"><</span><span class="tag-name">table</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"500"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"30"</span><span> </span><span class="attribute">border</span><span>=</span><span class="attribute-value">"1"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>      <span class="tag"><</span><span class="tag-name">tr</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">"middle"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#A5F5BF"</span><span> </span><span class="tag">></span><span> </span></span></li>
<li><span>        <span class="tag"><</span><span class="tag-name">th</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"100"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"25"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">"middle"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"style1"</span><span class="tag">></span><span>项目名</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">th</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>        <span class="tag"><</span><span class="tag-name">th</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"60"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">"middle"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"style1"</span><span class="tag">></span><span>大小</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">th</span><span class="tag">></span><span> </span></span></li>
<li><span>        <span class="tag"><</span><span class="tag-name">th</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"150"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">"middle"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"style1"</span><span class="tag">></span><span>创建日期</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">th</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>        <span class="tag"><</span><span class="tag-name">th</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"180"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">"middle"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"style1"</span><span class="tag">></span><span>最后修改时间</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">th</span><span class="tag">></span><span> </span></span></li>
<li><span>      <span class="tag"></</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span>  </span></span></li><li><span>    if(!isset($_GET[mulu])empty($_GET[mulu]))$<span class="attribute">dqml</span><span>=</span><span class="attribute-value">getcwd</span><span>();//获得脚本目录 </span></span></li><li class="alt"><span>        else $<span class="attribute">dqml</span><span>=$_GET[mulu]; </span></span></li><li><span>    chdir($dqml);//改变当前目录 </span></li><li class="alt"><span>        echo "当前目录:".getcwd()."<span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>"; </span></span></li>
<li><span>    $<span class="attribute">ml</span><span> = </span><span class="attribute-value">opendir</span><span>($dqml);  //打开目录 </span></span></li>
<li class="alt"><span>    while ($<span class="attribute">hqml</span><span> = </span><span class="attribute-value">readdir</span><span>($ml)){ //循环读取目录中的目录及文件 </span></span></li>
<li><span>    echo "<span class="tag"><</span><span class="tag-name">tr</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">'center'</span><span> </span><span class="attribute">valign</span><span>='middle'</span><span class="attribute-value">bgcolor</span><span>='#A5F5BF'</span><span class="tag">></span><span>"; </span></span></li>
<li class="alt"><span>        if(is_dir($hqml)){  //判断是目录 </span></li>
<li><span>           if($<span class="attribute">hqml</span><span>=="."){ </span></span></li>
<li class="alt"><span>              $<span class="attribute">mulu</span><span>=</span><span class="attribute-value">getcwd</span><span>();//显示当前目录 </span></span></li>
<li><span>       echo "<span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=$php_self?</span><span class="attribute">mulu</span><span>=$mulu</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">'style1'</span><span class="tag">></span><span>锁定</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span>"; } </span></span></li>
<li class="alt"><span>           elseif($<span class="attribute">hqml</span><span>==".."){ </span></span></li>
<li><span>              $<span class="attribute">mulu</span><span>=</span><span class="attribute-value">getcwd</span><span>()."\\.."; //上级目录 </span></span></li>
<li class="alt"><span>              echo "<span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=$php_self?</span><span class="attribute">mulu</span><span>=$mulu</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">span</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">'style1'</span><span class="tag">></span><span>上级目录</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span>"; </span></span></li>
<li><span>           }else{ </span></li>
<li class="alt"><span>              $<span class="attribute">mulu</span><span>=</span><span class="attribute-value">getcwd</span><span>()."\\$hqml";  //子目录 </span></span></li>
<li><span>              echo "<span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=$php_self?</span><span class="attribute">mulu</span><span>=$mulu</span><span class="tag">></span><span>$hqml</span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span>"; }  </span></span></li>
<li class="alt"><span>           }else{  </span></li>
<li><span>           $<span class="attribute">ext</span><span>=</span><span class="attribute-value">substr</span><span>($hqml,strrpos($hqml,".")); </span></span></li>
<li class="alt"><span>    if(strtoupper($ext)==".PHP"strtoupper($ext)==".TXT"){ </span></li>
<li><span>        $<span class="attribute">mulu</span><span>=</span><span class="attribute-value">getcwd</span><span>(); </span></span></li>
<li class="alt"><span>        echo "<span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=./example25.php?</span><span class="attribute">mulu</span><span>=$mulu&</span><span class="attribute">filename</span><span>=$hqml&</span><span class="attribute">type</span><span>=$ext</span><span class="tag">></span><span>$hqml</span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span>";  </span></span></li>
<li><span>        }else{ </span></li>
<li class="alt"><span>        echo "$hqml"; }  } </span></li>
<li><span>    if(is_dir($hqml)) $<span class="attribute">file_size</span><span>=</span><span class="attribute-value">"目录"</span><span>; </span></span></li>
<li class="alt"><span>        else $<span class="attribute">file_size</span><span>=</span><span class="attribute-value">round</span><span>(filesize($hqml)/1024)."k"; </span></span></li>
<li><span>           echo "<span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">'center'</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">'middle'</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">'#A5F5BF'</span><span class="tag">></span><span>$file_size</span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span>"; </span></span></li>
<li class="alt"><span>        $<span class="attribute">create_time</span><span>=</span><span class="attribute-value">date</span><span>("y-m-d h:i:sA",filectime($hqml)); </span></span></li>
<li><span>           echo "<span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">'center'</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">'middle'</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">'#A5F5BF'</span><span class="tag">></span><span>$create_time</span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span>"; </span></span></li>
<li class="alt"><span>        $<span class="attribute">update_time</span><span>=date("y-m-d h:i:sA",filemtime($hqml)); </span></span></li>
<li><span>           echo "<span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">'center'</span><span> </span><span class="attribute">valign</span><span>=</span><span class="attribute-value">'middle'</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">'#A5F5BF'</span><span class="tag">></span><span>$update_time</span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span>"; }   </span></span></li>
<li class="alt"><span>    closedir($ml); <span class="tag">?></span><span> </span></span></li>
<li><span>    <span class="tag"></</span><span class="tag-name">table</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"></</span><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"></</span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li>
</ol>



声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。