dtsjq28482 2011-11-20 20:15
浏览 42
已采纳

在php中分页文件列表

I have php code for list all ".swf" files in a folder. (The name of the files is always: "99-dd-mm-YY_HH-mm-ss.swf", example: "01-19-06-2011_18-40-00.swf". When I have more than 500 files in the folder is complicated to see and to refresh the page.

I need paginate the list of files.

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title></title>
<script type="text/javascript">
function submitform()
{    
  document.myform.submit();
}
</script>
</head>
<body>
<form name="myform" action="some.php" method="post">
<?php
   echo "
<br>
";


echo "<a href='javascript:this.location.reload();' style='color: #000000; font-weight: normal'>Refresh</a></br>";
   echo "<tr>
<td>
<a href='javascript:javascript:history.go(-1)'>
";
   echo "<img src='../../inc/img/back.png' alt='Back'";
   echo " border=0>
";
   echo "<b>&nbsp;Back</b></a></td>
";
   echo "
</tr>
";
   echo "
<br>

<br>
";
$folder='.';
function order($a,$b){
global $folder;
$directory='.';
return strcmp(strtolower($a), strtolower($b));
}
$folder=opendir($folder);
while($files=readdir($folder)){

$ext = pathinfo($files, PATHINFO_EXTENSION);
if ($ext == 'swf')  {  //con esta línea saco el nombre index.php del listado
$file[]=$files;
usort($file, "order");
}
}
$n = 0;
foreach($file as $archiv){
   $n = $n + 1;
   $day = substr($archiv, 3,10);
   $day = str_replace("-","/", $day);
   $hour = substr($archiv, 14,8);
   $hour = str_replace("-",":", $hour);
   echo "<img alt='Ver $archiv' src='../../inc/img/video.png'> Video $n, Día: $day, hour: $hour
 ";
   echo "<input type='submit' name='xxx' value='$archiv'></td>
";
   echo "
</tr>
";
   echo "<br>";
}
closedir($folder);
   echo "
<br>
";
   echo "<tr>
<td>
<a href='javascript:javascript:history.go(-1)'>
";
   echo "<img src='../../inc/img/back.png' alt='Back'";
   echo " border=0>
";
   echo "<b>&nbsp;Back</b></a></td>
";
   echo "
</tr>
";
?>
</form>
</body>
</html>
  • 写回答

3条回答 默认 最新

  • duanhan5230 2011-11-26 17:11
    关注

    I used this code for simple pagination

    <?php
    // Include the pagination class
    include 'pagination.class.php';
    // Create the pagination object
    $pagination = new pagination;
    
    // some example data
    foreach (range(1, 100) as $value) {
    $products[] = array(
    'Product' => 'Product '.$value,
    'Price' => rand(100, 1000),
    );
    }
    
    // If we have an array with items
    if (count($products)) {
    // Parse through the pagination class
    $productPages = $pagination->generate($products, 20);
    // If we have items
    if (count($productPages) != 0) {
    // Create the page numbers
    echo $pageNumbers = '<div>'.$pagination->links().'</div>';
    // Loop through all the items in the array
    foreach ($productPages as $productID => $productArray) {
    // Show the information about the item
    echo '<p><b>'.$productArray['Product'].'</b> 243'.$productArray['Price'].'</p>';
    }
    // print out the page numbers beneath the results
    echo $pageNumbers;
    }
    }
    ?>
    

    Here there is pagination class and the example for download: http://lotsofcode.com/php/php-array-pagination.htm

    Thanks for all!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败