在PHP中的分页列表文件 [英] Paginate list of files in php

查看:135
本文介绍了在PHP中的分页列表文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有php代码列出文件夹中的所有.swf文件。 (文件的名称总是:
99-dd-mm-YY_HH-mm-ss.swf,例如:01-19-06-2011_18-40-00.swf。
当我在文件夹中有超过500个文件时,很难看到并刷新页面。



我需要分页文件列表。


$ b $ $ p $
$ lt; 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 =myformaction =some.phpmethod =post>
<?php
echo\\\
< br> \\\
;


echo< a href ='javascript:this.location.reload();'style ='color:#000000; font-weight:normal'>刷新< / a><< ;
echo< tr> \\\
< td> \\\
< a href ='javascript:javascript:history.go(-1)'> \\\
;
echo< img src ='.. / .. / inc / img / back.png'alt ='Back';
echoborder = 0> \\\
;
echo< b>& nbsp;返回< / b>< / a>< / td> \\\
;
echo\\\
< / tr> \\\
;
echo\\\
< br> \\\
\\\
< br> \\\
;
$ folder ='。';
函数顺序($ a,$ b){
全局$文件夹;
$ directory ='。';
返回strcmp(strtolower($ a),strtolower($ b));
}
$ folder = opendir($ folder);
while($ files = readdir($ folder)){

$ ext = pathinfo($ files,PATHINFO_EXTENSION);
if($ ext =='swf'){//创建一个新的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\\ n;
echo< input type ='submit'name ='xxx'value ='$ archiv'>< / td> \\\
;
echo\\\
< / tr> \\\
;
echo< br>;
}
closedir($文件夹);
echo\\\
< br> \\\
;
echo< tr> \\\
< td> \\\
< a href ='javascript:javascript:history.go(-1)'> \\\
;
echo< img src ='.. / .. / inc / img / back.png'alt ='Back';
echoborder = 0> \\\
;
echo< b>& nbsp;返回< / b>< / a>< / td> \\\
;
echo\\\
< / tr> \\\
;
?>
< / form>
< / body>
< / html>


解决方案

我用这个简单的分页代码

 <?php 
//包括分页类
include'pagination.class.php';
//创建分页对象
$ pagination = new pagination;

//一些示例数据
foreach(范围(1,100)为$ value){
$ products [] = array(
'Product'=> ;'Product'。$ value,
'Price'=> rand(100,1000),
);


//如果我们有一个数组
if(count($ products)){
//通过分页类解析
$ productPages = $ pagination-> generate($ products,20);
//如果我们有项目
if(count($ productPages)!= 0){
//创建页码
echo $ pageNumbers ='< div>' 。$ pagination->链接()。 '< / DIV>';
//遍历数组中的所有元素
foreach($ productPages as $ productID => $ productArray){
//显示有关项目的信息
echo' < p为H.;< b取代; '$ productArray [ '产品']' < / b个243’ [价格]< $ productArray。; / p为H.;
}
//输出结果下方的页码
echo $ pageNumbers;
}
}
?>

这里有分页类和下载的例子:
http://lotsofcode.com/php/php-array-pagination.htm



感谢所有!


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 "\n<br>\n";


echo "<a href='javascript:this.location.reload();' style='color: #000000; font-weight: normal'>Refresh</a></br>";
   echo "<tr>\n<td>\n<a href='javascript:javascript:history.go(-1)'>\n";
   echo "<img src='../../inc/img/back.png' alt='Back'";
   echo " border=0>\n";
   echo "<b>&nbsp;Back</b></a></td>\n";
   echo "\n</tr>\n";
   echo "\n<br>\n\n<br>\n";
$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\n ";
   echo "<input type='submit' name='xxx' value='$archiv'></td>\n";
   echo "\n</tr>\n";
   echo "<br>";
}
closedir($folder);
   echo "\n<br>\n";
   echo "<tr>\n<td>\n<a href='javascript:javascript:history.go(-1)'>\n";
   echo "<img src='../../inc/img/back.png' alt='Back'";
   echo " border=0>\n";
   echo "<b>&nbsp;Back</b></a></td>\n";
   echo "\n</tr>\n";
?>
</form>
</body>
</html>

解决方案

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!

这篇关于在PHP中的分页列表文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆