您的位置:首页 > 编程语言 > PHP开发

php文件操作,文件夹列表,文件列表

2007-06-06 16:21 417 查看
下面是一个文件夹的文件列表操作. 主要想实现文件夹的点进点出操作. 由于需求变化, 没有完成. 思路主要是先将根目录下的文件列表显示出来, 根目录下没有向上的链接. 由于是在WEB页面上实现, 所以点开的操作主要是通过ajax实现, 在javascript函数 list()中来实现. 思路主要是这样, 怕忘记,做个记录先...

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$filepath = $_SERVER['DOCUMENT_ROOT'];
$Path = $filepath.urldecode('/resource/theme'); //最好用session设置路径安全,这是我的路径
$handle = opendir($Path);

while($file = readdir($handle))
{
$newpath=$Path."/".$file;

if(is_dir($newpath))
{
if($file!=".." && $file!=".")
{
$tree[0]['f'][] = array(
'name' => $file,
'path' => $newpath
);
}
}
else
{
$tree[0]['l'][] = array(
'name' => $file,
'path' => $newpath
);
}
}

?>
<div id="theme" style="display:none;">
<div id="file">
<table width="90%" bgcolor="#FFFFFF">
<tr>
<?php
$i = 0;
foreach($tree[0]['f'] as $value)
{
$i++;
?>
<td align="left">
<img alt="文件夹,双击打开" src="/resource/images/folder_close.gif">
 <?php echo $value['name']; ?>
</td>
<?php
if($i%3 == 0)
echo '</tr><tr>';
}

?>
</tr>

</table>
</div>
<div id="pic">theme</div>
</div>
<script type="text/javascript">
<!--
function list(name, path)
{

}
//-->
</script>

at 12-27,post by 221.221.103.xxx
扩展方法,根据文件夹下的图片来生成小图片 并入库. 入库内容请自己修改. 这里是特殊框架下的做法

public function makesmallpic()
{
set_time_limit(0);

$filepath = $_SERVER['DOCUMENT_ROOT'];

$files = array(
'old','washabi','cool','yellow','babi','duogu','gumo','jimi','kkome','new','shengxiao','wish'
);

$this ->loadModel('ThemeModel');

foreach($files as $value)
{

$Path = $filepath.urldecode('/resource/theme/' . $value);//最好用session设置路径安全

$handle = opendir($Path);

while($file = readdir($handle))
{
$newpath=$Path.'/'.$file;

if(!is_dir($newpath) && $file!='Thumbs.db')
{
if(!file_exists($Path.'/small'))
mkdir($Path."/small", 0744);

$smallfile = $Path.'/small/'.$file;
makeThumb($newpath, $smallfile, 153, 115, 1|8, 1, 0, 0);

$flag = ThemeModel::makesmallpic(
array(
'name' => $file,
'url' => 'http://file.magicliu.cn/file/getoldfile/theme/'.$value.'/'.$file,
'surl' => 'http://file.magicliu.cn/file/getoldfile/theme/'.$value.'/small/'.$file,
'tname' => $value //图片类型
));
}
}
echo $value.'文件夹已经操作完成...';
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: