提示array_mar未定义啊 Fatal error: Call to undefined function array_mar() in E:\php\readir.php on line 49
哦!不好意思,手误! array_map
还是报错 Warning: array_map() expects parameter 1 to be a valid callback, function 'filetime' not found or invalid function name in E:\php\readir.php on line 48filetime能直接放到里面去?
filemtime 那是你写错了,我没注意
Warning: filemtime() [function.filemtime]: stat failed for 001.tar.gz in E:\php\readir.php on line 48还是一堆错误额,我本来用fileatime获取文件大小的时候是要加上文件的绝对路径的 fileatime($patch.$_GET['id'].'/'.$file)
本帖最后由 xuzuning 于 2011-07-14 17:45:40 编辑
$f = array(); while ($file = readdir($handle))
{ if ($file!="." && $file!="..") array_push($f,$file);
则文件的修改时间数组为
$t = array_mar('filetime', $f);用 array_multisort 对这两个数组排序
array_multisort($t, SORT_DESC, $f);输出时用下标关联两个数组
for($i=0; $i<count($f); $i++)
echo "<tr><td>{$f[$i]}</td><td>{$t[$i]}</td></tr>";
filetime取出的时间默认就是时间戳、无需转换、我先试试xuzhuning的方法
我一般都用 glob 简单实用,并且返回的文件名是含路径的,不像 readdir 只返回文件名$f = glob('test/*');
就得到了 test 目录下的所有文件名,包括子目录名
提示array_mar未定义啊
Fatal error: Call to undefined function array_mar() in E:\php\readir.php on line 49
array_map
还是报错
Warning: array_map() expects parameter 1 to be a valid callback, function 'filetime' not found or invalid function name in E:\php\readir.php on line 48filetime能直接放到里面去?
那是你写错了,我没注意
Warning: filemtime() [function.filemtime]: stat failed for 001.tar.gz in E:\php\readir.php on line 48还是一堆错误额,我本来用fileatime获取文件大小的时候是要加上文件的绝对路径的
fileatime($patch.$_GET['id'].'/'.$file)
$f = array();
while ($file = readdir($handle))
{
if ($file!="." && $file!="..")
array_push($f,$file);
}
$t = array_map('filemtime',$f);
array_multisort($t,SORT_DESC,$f);
for($i=0;$i<count($f);$i++)
{
echo "<pre>";
print_r($i);
嘿嘿
readdir 返回的是不带路径的文件名!
filemtime 需要的是带路径的文件名!
这能怪谁呢?
$patch='./dbbak/';
//$handle = opendir($patch.$_GET['id']);if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="150px;">上传时间</th>
<th width="80px">下载</th>
</table>';
while($file = glob($handle))
print_r($file);
Warning: glob() expects parameter 1 to be string, resource given in E:\php\readir.php on line 39
不能这么弄么?
glob()指定第一个参数问字符串,你给的是资源。glob($patch.$_GET['id']);直接这样就行。
//$handle = opendir($patch.$_GET['id']);if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="150px;">上传时间</th>
<th width="80px">下载</th>
</table>';
print_r(glob($patch.$_GET['id']));Array ( [0] => ./dbbak/8031 ) 我这样还是取不到数据呀
基本上搞定了、不过还有个问题、
用glob返回的有地址的文件名也有点不方便的地方、如果我在现实文件名的时候、不需要地址、怎么去掉呢?
对于下载链接、和filemtime获取文件大小、直接返回文件真实地址蛮方便的、哈哈