文本版|topic 高级搜索
   名人堂 帮助 论坛制度 意见反馈 | 首页 博客 周新贴 专题 求职 读书
RSS 底部
 
社区导航: 专家门诊   网络技术   操作系统   数据库   程序设计   系统应用   考试认证   CIO及信息化   站长交流   综合交流   下载基地  51CTO产品服务 设为首页 | 收藏本站
51CTO技术论坛» Php » 远程文件管理       [ 打印]  [ 订阅]  [ 收藏]  [ 推荐给朋友]   [ 本帖文本页]

论坛跳转:
     
标题: [转载] 远程文件管理  ( 查看:481  回复:0 )   
 
123187643
技术员  点击可查看详细



帖子 47
精华 0
无忧币 265
积分 255
阅读权限 30
注册日期 2007-8-20
最后登录 2007-8-24 离线

[查看资料]  [发短消息]  [Blog
       
发表于:2007-8-24 10:22   标题:远程文件管理
上一帖 |
<?php
if ($_GET['task']) {
        if ($_GET['task'] == 'edit') {
                $file = realpath($_GET['file']);
                $fp  = fopen($file, 'a+');
                if (filesize($file) > 0) {  
                        $content = fread($fp, filesize($file));
                }
                echo "
                <form action='index.php?fileDir=" . $_GET['fileDir'] . "&task=save&file=" . $_GET['file'] . "' method='post'>
                <textarea name='content' style='width:500px;height:200px;' >" . $content . "</textarea>
                <br /><input type='submit' value='保存' />
                </form>
                ";
        } elseif ($_GET['task'] == 'del') {
                unlink(realpath($_GET['file']));
                echo $_GET['file'] . '<br />删除成功!';
        } elseif ($_GET['task'] == 'save') {
                $file = realpath($_GET['file']);
                $fp = fopen($file, 'w+');
                fwrite($fp, $_POST['content']);
                fclose($fp);
                echo $_GET['file'] . '<br />保存成功!';
        }
}

?>
<div>
        管理目录:<input type="text" id="dir" name="dir" /><button>提交</button>
</div>
<div>
        <a href="index.php?fileDir=<?php echo $_GET['fileDir']; ?>../">跳转到上级目录</a>
</div>
<table>
        <thead>
                <tr>
                        <th>文件类型</th>
                        <th>文件名</th>
                        <th>文件大小</th>
                        <th>编辑</th>
                        <th>删除</th>
                </tr>
        </thead>
        <tbody>
<?php
//$fileDir = str_replace('\\', '/', realpath($_GET['fileDir'])) . '/';
$fileDir = $_GET['fileDir'];
if (!$fileDir) {
        $fileDir = './';
}
$handle = opendir($fileDir);
while ($filename = readdir($handle)) {
        if ($filename != '.' && $filename != '..') {
                if (is_file($fileDir . $filename)) {
                        $fileType = '文件';
                } else {
                        $fileType = '<a href="index.php?fileDir=' . $fileDir . $filename . '/">目录';
                }
                echo '
                <tr>
                        <td> ' . $fileType . ' </td>
                        <td> ' . $filename . ' </td>
                        <td> ' . filesize($fileDir . $filename). ' </td>
                        <td> <a href="index.php?task=edit&file=' . $fileDir . $filename . '&fileDir=' . $fileDir . '">编辑</a> </td>
                        <td> <a href="index.php?task=del&file=' . $fileDir . $filename . '&fileDir=' . $fileDir . '">删除</a> </td>
                </tr>
                ';      
        }      
}



论坛活动:测测你对IT技术大会的了解指数(赠微软礼品、无忧币)
2007-8-24 10:221楼
[ 顶部 ]
     
论坛跳转:  

| | |

标记已读 · 删除论坛Cookies · 文本版 · WAP
 
| 诚征版主 | 版主堂 | 意见建议 | 大史记 | 论坛地图
Copyright©2005-2008 51CTO.COM  Powered by Discuz!
本论坛言论纯属发布者个人意见,不代表51CTO网站立场!如有疑义,请与管理员联系。
京ICP备05051492号