我这个函数是写在这个文件的后面的、运行这页代码的时候会提示Fatal error: Call to undefined function page() in E:\php\readir.php on line 52函数必须在调用代码之前被声明么?为什么我看到另外一断代码是可以将声明函数放在调用代码之后的呢?$patch='./dbbak/';
if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="200px;">上传时间</th>
<th width="30px">下载</th>
</table>';
}
$f = array("1","2","3","4","5","6","7","8","9","10","11");
// $f = glob($patch.$_GET['id'].'/*');
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$r = page($f,2,$page);
foreach($r["source"] as $value){
echo $value.'
<br/>
'.$r["page"];
}
function page($f,$pagesize,$current)
{
$_return = array();
$total = ceil(count($f)/$pagesize);
$prev = (($current-1)<=0 ? "1":($current-1));
$next =($current+1>=$total ? $total:$current+1);
$current =($current>($total) ? ($total):$current);
$start = ($current-1)*$pagesize;
for($i=$start;$i<($start+$pagesize);$i++)
{
array_push($_return,$f[$i]);
}
$pagearr["source"]=$_return;
$pagearr["page"]="<a href=\"?acticon=barfilelist&page=1\">first</a> <a href=\"?acticon=barfilelist&page={$prev}\">prev</a> <a href=\"?acticon=barfilelist&page={$next}\">next</a> <a href=\"?acticon=barfilelist&page={$total}\">end</a>";
return $pagearr;
}/*
if ($f!="." && $f!="..")
{
$t = array_map('filemtime',$f);
$s = array_map('filesize',$f);
array_multisort($t,SORT_DESC,$f);
}
for($i=0;$i<count($f);$i++)
{
echo '<table id="tb2">
<td width="80px">'.$_GET['id'].'</td>
<td width="200px">'.substr($f[$i],19).'</td>
<td width="80px">'.intval(($s[$i])/(1024)).'KB</td>
<td width="200px">'.date('Y-m-d H:s',$t[$i]).'</td>
<td width="30px"><a href="http://localhost/'.$f[$i].'"><img alt="点击下载" align="center" style="border:0;" src="./image/download2.gif" /></a></td>
</table>';
} */
closedir($handle);
if ($handle = opendir($patch.$_GET['id']))
{
echo '<table id="tb1">
<th width="80px">客户编号</th>
<th width="200px">文件名</th>
<th width="80px">文件大小</th>
<th width="200px;">上传时间</th>
<th width="30px">下载</th>
</table>';
}
$f = array("1","2","3","4","5","6","7","8","9","10","11");
// $f = glob($patch.$_GET['id'].'/*');
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$r = page($f,2,$page);
foreach($r["source"] as $value){
echo $value.'
<br/>
'.$r["page"];
}
function page($f,$pagesize,$current)
{
$_return = array();
$total = ceil(count($f)/$pagesize);
$prev = (($current-1)<=0 ? "1":($current-1));
$next =($current+1>=$total ? $total:$current+1);
$current =($current>($total) ? ($total):$current);
$start = ($current-1)*$pagesize;
for($i=$start;$i<($start+$pagesize);$i++)
{
array_push($_return,$f[$i]);
}
$pagearr["source"]=$_return;
$pagearr["page"]="<a href=\"?acticon=barfilelist&page=1\">first</a> <a href=\"?acticon=barfilelist&page={$prev}\">prev</a> <a href=\"?acticon=barfilelist&page={$next}\">next</a> <a href=\"?acticon=barfilelist&page={$total}\">end</a>";
return $pagearr;
}/*
if ($f!="." && $f!="..")
{
$t = array_map('filemtime',$f);
$s = array_map('filesize',$f);
array_multisort($t,SORT_DESC,$f);
}
for($i=0;$i<count($f);$i++)
{
echo '<table id="tb2">
<td width="80px">'.$_GET['id'].'</td>
<td width="200px">'.substr($f[$i],19).'</td>
<td width="80px">'.intval(($s[$i])/(1024)).'KB</td>
<td width="200px">'.date('Y-m-d H:s',$t[$i]).'</td>
<td width="30px"><a href="http://localhost/'.$f[$i].'"><img alt="点击下载" align="center" style="border:0;" src="./image/download2.gif" /></a></td>
</table>';
} */
closedir($handle);
//测试没问题
page('test');
function page($str) { echo $str; }
line 52 我不知道是哪个地方,因为你用的开发工具可能不一样代码里唯一用到page的地方是
$r = page($f,2,$page);
没有发现不妥的地方