Странициране особено

MontefuckeR

Registered
Трябва ми код за странициране обаче без БД !
защото файловете който искам да се страницират са записани в папка
 
hrischo каза:
http://web-tourist.net/login/login/view.php?st=1619
това е от файл а аз искам от папка
Едит:
при мен ъплоаднатите файлове влизат в папка "upload" и от там ги изкарвам с код в индекса на сайта като имената им обаче страницата много се разтяга надолу като са повече файлове.
 
Код:
<?php 
//колко резултата на страница
$pp = "25"; 
//колко резултата на страница
//задаваме папката 
$dir = "./"; 
//задаваме папката 
$page=$_GET['page'];
if(!$_GET['page'])
{
$page="1";
}
$limit = ($pp*$page)-$pp;


$dh = opendir($dir); 
while (false !== ($filename = readdir($dh))) 
	{
	if ($filename!="." && $filename!=".." && $filename!="Thumb.db")
		{
		if(is_dir($dir.$filename)) 
            { 
			$files[] = "[DIR] ".$filename; 
			}
		else
			{
			$files[] = "[FILE] <a href='".$dir.$filename."'>".$filename."</a>";
			}
		}
	} 

$count = count($files); 

for($i=$limit; $i<=($limit+$pp); $i++)
	{
	echo $files[$i]."<br>";
	}


echo "<br>";

//от тук започва кода за показването на страниците
$total=ceil($count/$pp);
for($i=1 ; $i<=$total ; $i++)
{
if(($page)==$i)
{
echo "[".$i."] ";
}
else
{
echo "<a href=\"?page=".$i."\">".$i."</a> ";
}
}

?>
 
Значи преди резултатите ми излизаха в табличка така добре бяха подредени. Искам и сега след като може да се страницират пак да излизат в таблица ето ми кодчетата:

Покажи в червено кое променяш моля :roll:


upload.php
Код:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<tr>
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>
<input name="ufile" type="file" id="ufile" size="60" /></td>
</tr>
<tr>
<input type="submit" name="Submit" value="Качи" />
</tr>
</table>
</td>
</form>
</tr>
</table>
</sup></small>
</center>
</sup></small>
</center>
</center>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Search</title>
</head>

<body>
<center>
<td><strong>Search Engine</strong></td>
<form action="search.php" method="post">
<input type="text" name="searched">
<input type="submit" value="Търси !">
</form>
</html>
<?
$dir = "upload/"; // Избираме директорията, от която ще индексираме файловете
if(!is_dir($dir))
{
mkdir($dir); // Проверяваме дали директорията съществува, ако не я създаваме
}
$dh = opendir($dir); // Подготвяме за четене (отваряме) директорията
print "<h3>Files в $dir</h3><table width=\"90%\" align=\"center\" border=\"1\"><tr><td style=\"text-align:center\">Име на file:</td></tr>";
while($file = readdir($dh)) // Четем файловете от директорията (този цикъл помага да индексираме всички файлове)
{
if($file != "." and $file != "..") // Не индексираме "." и ".."
{
$lower = strtolower($file);
if(!eregi(".ht",$file)) // Така можете да не индексирате дадени файлове
{
print "<tr><td><a href=\"$dir$file\">$file</a></td></tr>"; // Когато поставяте линк не забравяйте да добавите и променливата $dir
}
}
}
print "</table>"; 
?>
upload_ac.php
Код:
<?php
session_start();
?>
<?
//файловете ще се съхраняват в папката upload
//$HTTP_POST_FILES['ufile']['name']; = качва името на файла
//за пример качваме файл на име picture.gif . $path то ще бъде качено - /picture.gif
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "<b>File бе качен успешно !<BR/>";

//$HTTP_POST_FILES['ufile']['name'] = името на файла
//$HTTP_POST_FILES['ufile']['size'] = големината на файла
//$HTTP_POST_FILES['ufile']['type'] = мястото на файла
echo "Име:".$HTTP_POST_FILES['ufile']['name']."<BR/>";
echo "Тип:".$HTTP_POST_FILES['ufile']['type']."<BR/>";
}
else
{
echo "<b><font color=red>Бе открита грешка</b></font>";
}
}
?>
search.php
Код:
<?php
$flag=0;
$dir="upload/";
if(isset($_POST['searched'])) {
foreach(glob($dir."*") as $file) {
if(@eregi($_POST['searched'], str_replace($dir, "", $file))) {
echo("<a href='".$file."' target=_blank>".str_replace($dir, "", $file)."</a><br />\n");
$flag+=1;
}
}
if($flag==false) {
echo("Няма намерени файлове.");
}
}
?>
</center>
</body>

</html>
 
10 min раота
търсачка
Код:
<form action="" method="GET">
<input type="text" name="search" value="<?php echo htmlspecialchars(stripslashes($_GET['search']));?>">
<input type="submit" value="Търси">
</form>
<?php
$flag=0;
$dir="images/";
$search = $_GET['search'];
$broinastranica = 2;
function searching($unset = "")
{
	global $dir,$search,$broinastranica;
	$each = array();
	$i = 0;
	$k = 1;
	foreach(glob($dir."*") as $file) 
	{
		$file =  str_replace($dir,'',$file);
		if(eregi($search,$file))
		{
			if($i == $broinastranica)
			{
				$i = 0;
				$k++;
			}
			$i++;
			$each[][$k] = strtolower($file);
		}
	}
	return $each;
}
function pager($vararray)
{
global $search,$_GET,$_SERVER;
		$page_set = array();
		$paginator = '';
	foreach($vararray as $b=>$stranici)
	{
	list($stranici) = @each($stranici);
		if ( empty($page_set[$stranici]) )
		{
			$page_set[$stranici] = 1;
			$paginator .= ($_GET['page'] == $stranici) ? '<b>'.$stranici.'</b>' : '<a href="'. $_SERVER['PHP_SELF'] .'?page='.$stranici.'&search='.htmlspecialchars($search).'">'.$stranici.'</a> ';
		
		}
	}
	return $paginator;
}
$page = (intval($_GET['page']) > 0 ) ? intval($_GET['page']) : 1;
if($search)
{
$files = searching();
	for($i = 0; $i<count($files);$i++)
	{
		echo $files[$i][$page].'<BR>';
	}
echo pager($files);
}
?>
 
Код:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<tr>
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>
<input name="ufile" type="file" id="ufile" size="60" /></td>
</tr>
<tr>
<input type="submit" name="Submit" value="Качи" />
</tr>
</table>
</td>
</form>
</tr>
</table>
</sup></small>
</center>
</sup></small>
</center>
</center>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Search</title>
</head>

<body>
<center>
<td><strong>Search Engine</strong></td>
<form action="search.php" method="GET">
<input type="text" name="search">
<input type="submit" value="Търси !">
</form>
</html>
<?php
$dir="images/";
$search = $_GET['search'];
$broinastranica = 2;
function searching()
{
	global $dir,$search,$broinastranica;
	$each = array();
	$i = 0;
	$k = 1;
	foreach(glob($dir."*") as $file) 
	{
		$file =  str_replace($dir,'',$file);
		if(eregi($search,$file))
		{
			if($i == $broinastranica)
			{
				$i = 0;
				$k++;
			}
			$i++;
			$each[][$k] = strtolower($file);
		}
	}
	return $each;
}
function pager($vararray)
{
global $search,$_GET,$_SERVER;
		$page_set = array();
		$paginator = '';
	foreach($vararray as $b=>$stranici)
	{
	list($stranici) = @each($stranici);
		if ( empty($page_set[$stranici]) )
		{
			$page_set[$stranici] = 1;
			$paginator .= ($_GET['page'] == $stranici) ? '<b>'.$stranici.'</b>' : '<a href="'. $_SERVER['PHP_SELF'] .'?page='.$stranici.'&search='.htmlspecialchars($search).'">'.$stranici.'</a> ';
		
		}
	}
	return $paginator;
}
if(!is_dir($dir))
{
mkdir($dir); // Проверяваме дали директорията съществува, ако не я създаваме
}
$page = (intval($_GET['page']) > 0 ) ? intval($_GET['page']) : 1;

print "<h3>Files в $dir</h3><table width=\"90%\" align=\"center\" border=\"1\"><tr><td style=\"text-align:center\">Име на file:</td></tr>";
if($search)
{
$files = searching();
$var = array();
	for($i = 0; $i<count($files);$i++)
	{
		if(!empty($files[$i][$page]))
		{
	echo "<tr><td><a href=\"".$dir . $files[$i][$page] ."\">". $files[$i][$page] ."</a></td></tr>";
		}
	}
echo pager($files);
}
print "</table>";
това и сам можеше да си го направиш не е трудно да се копира O_o
 

Back
Горе