Click here to Close
打印

[原创] 美化Apache+PHP浏览本地文件的php程序

美化Apache+PHP浏览本地文件的php程序

看到http://www.weiphone.com/viewthread.php?tid=67076&highlight=apache这个帖子,不免心动,自己动手改了些代码和图标:
具体修改内容如下:
1、日期格式改为习惯的“年-月-日”;
2、文件夹和文件截取长度加长;
3、替换了.txt,.xls,.doc,.pdf,.png,.gif类型文件的图标;
4、支持中文文件名(源文件为gb2312编码,我机子上无法显示中文文件名,我改成utf8就可以了);
希望对大家有用。
具体如何安装Apache、PHP以及如何使用这个php程序请看原贴:http://www.weiphone.com/viewthread.php?tid=67076&highlight=apache
截图:

[ 本帖最后由 babyshan 于 2008-3-15 23:22 编辑 ]

附件

iphone-phpbox-v102.rar (56.63 KB)

2008-3-15 23:20, 下载次数: 315

IMG_0065.JPG (66.09 KB)

2008-3-15 23:22

IMG_0065.JPG

IMG_0066.JPG (55.75 KB)

2008-3-15 23:22

IMG_0066.JPG

IMG_0067.JPG (47.2 KB)

2008-3-15 23:22

IMG_0067.JPG

本帖最近评分记录
  • elwes 人气 +5 受益了 2008-4-26 14:32
真是太好了!!非常喜欢!谢谢!
可是这里关于apache和php的帖子人气都不是很旺阿!其实是很好很强大的功能阿!

TOP

受益良多,顶一下兄台
顶起来,好东西啊,谢谢
其实这个帖子合并在ericfish的原帖中也许更便于大家的使用

另,不得不说一句楼主你的“美化”感觉有点……
呵呵,感谢楼上的批评,发这个东东只是希望这东东能够对大家有用,另外如何将这个贴子合并到ericfish的原帖中,还望指教。
好像确实不错,晚上回家装哈哈
立马安装,谢!
安装了但打开127.0.0.1/index.php 看到的是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>iPhone PHPBox</title>

<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" type="text/css" href="css/list.css" />

<style type="text/css">

body > ul > li {
    font-size: 14px;
}

li .icon {
    display: block;
    position: absolute;
    margin: 0;
    left: 6px;
    top: 7px;
    text-align: center;
    font-size: 110%;
    letter-spacing: -0.07em;
    color: #93883F;
    font-weight: bold;
    text-decoration: none;
    width: 36px;
    height: 30px;
    padding: 7px 0 0 0;
}

li .desc {
    display: block;
    position: absolute;
    margin: 0;
    left: 54px;
    top: 20px;
    text-align: center;
    font-size: 110%;
    font-weight: bold;
    text-decoration: none;
    height: 30px;
    padding: 7px 0 0 0;
    background: none;
}

h2 {
    margin: 10px;
    color: slateblue;
}

p {
    margin: 10px;
}

h2 {
        margin: 8px;
}

h2.error {
        color: #f00;
}

</style>
</head>

<?php

$d='/';   // the current folder, ex: /pdf/2008/
if(isset($_GET['d']))
{
        $d=urldecode($_GET['d']);
}

if(!isset($rootdir))
{
        $rootdir=Getcwd().$d;
}

$findme   = '/';
$pos = strrpos(substr($d,0,strlen($d)-1), $findme);
$updir  = substr($d, 0, $pos+1);

$curfolder = 'localhost';
if($d != '/'){
        $curfolder = substr($d, $pos+1, strlen($d)-$pos-2);
}

?>

<body orient="landscape">
    <div class="toolbar">
        <h1 id="pageTitle"><?php echo($curfolder); ?></h1>
                <?php if($d != '/'): ?>
                <a style="display: inline;" id="backButton" class="button" href="<?php echo($_SERVER['PHP_SELF']."?d=".urlencode($updir)); ?>">返回</a>
                <?php endif; ?>
    </div>

        <ul style="left: 0%;" id="as" title="" selected="true">



<?php

myreaddir($rootdir);

function myreaddir($subdir)   //get all file and folders in subdir
{
          global $rootdir,$d;
          $icons=array("default"=>"default_file.gif","pdf"=>"pdf_file.gif","ppt"=>"ppt_file.gif","doc"=>"doc_file.gif","xls"=>"xls_file.gif","zip"=>"zip_file.gif","rar"=>"rar_file.gif","htm"=>"htm_file.gif","html"=>"html_file.gif","mov"=>"mov_file.gif","mp3"=>"mp3_file.gif","php"=>"php_file.gif","gif"=>"gif_file.gif","png"=>"png_file.gif","jpg"=>"jpg_file.gif","txt"=>"txt_file.gif");
   
          @chdir($subdir) or die ("error:could not change to this directory!");
          $dirobject=dir($subdir);
          $x=0;$y=0;$i=0;$j=0;
          while ($file=$dirobject->read())
          {
                        if(is_dir($file))         //if is folder
                        {
                                if($file=="." or $file=="..")   //"."&".."
                                {
//                                        echo "";
                                        continue;
                                }
                                $dir_array[$x++] = $file;
                                continue;
                        }
                        $file_array[$i++] = $file;
          }
          if($i>0) sort($file_array);
          if($x>0) sort($dir_array);
          while($x>0)
          {
                        echo "<li><a class=\"icon\"><img alt=\"Icon\" src=\"css/small_folder_icon.gif\"></a>";
                        echo "<a class=\"folder\" href=\"".$_SERVER['PHP_SELF']."?d=".urlencode($d.$dir_array[$y].'/')."\">".substr_for_url($dir_array[$y],42)."</a>";
                        echo "<a class=\"desc\">".date("Y-m-d", filemtime($dir_array[$y]))."</a></li>";   
                        $x--;$y++;
          }

          while($i>0)
          {
                        $file_type=strtolower(substr(strrchr($file_array[$j],"."),1));
                        $file_href="http://".$_SERVER['HTTP_HOST'].$d.$file_array[$j];
                        if(!isset($icons[$file_type])) $file_type="default";
                        echo "<li><a class=\"icon\"><img alt=\"Icon\" src=\"css/".$icons[$file_type]."\"></a>";
                        echo "<a class=\"file\" href=\"".$file_href."\">".substr_for_url(urldecode($file_array[$j]),42)."</a>";
                        echo "<a class=\"desc\">".(number_format(filesize($file_array[$j])/1024,2))."KB ".date("Y-m-d", filemtime($file_array[$j]))."</a></li>";      
                        $i--;$j++;
          }
          return;
}

function substr_for_url($str,$len=null)
{
        $totlelength = strlen($str);
       
        if ($len == null) $len = $totlelength;
        if ($len ==0) return "";
        if ($len >= $totlelength ) return $str;
        if ($len < $totlelength) $shorten = true;
       
        $subit=substr($str,0,$len);
       
        if($shorten) $subit = $subit.'...';
        return $subit;
}

?>
        </ul>

</body></html>

是不是我的php还没有设施好啊? 谢谢

TOP

是的,楼上的php没起来
深公网安备案证字第 4403101901155 号