PHP/MySQL | phpшники ХЕЛП!!
elfi, <?php
define( 'PERPAGE', 5 );
$directory = '123123';
$dir = new DirectoryItems($directory);
// Отфильтровываем все файлы, которые не являются изображениями
$dir->filter();
// Сортируем картинки
$dir->indexOrder = 'O = D';
// Общее количество изображений в директории
$totalCount = $dir->getCount();
// Текущая страница
if ( isset( $_GET['page'] ) )
$page = $_GET['page'];
else
$page = 1;
$numPages = ceil($totalCount/PERPAGE);
if ( $page < 1 ) $page = 1;
if ( $page > $numPages ) $page = $numPages;
// Получаем часть массива
$filearray = $dir->getFileArraySlice( ($page-1)*PERPAGE, PERPAGE);
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
foreach( $filearray as $value) {
$path = $dir->getDirectoryName().'/'.$value;
echo '<a href="download.php?image='.$path.'"><img src="download.php?image='.$path.'" alt="" /></a>'."\n";
}
// Создавать постраничную навигацию есть смысл, только если
// есть больше одной страницы
if($numPages > 1) {
// Создаем навигатор
$nav = new PageNavigator($totalCount, PERPAGE, $page);
echo $nav->getNavigator();
}
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.");
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.");
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
// исключить из массива все элементы с недопустимым расширением
public function filter(){
$extensions = array("jpg", "jpeg", "gif", "png");
foreach ($this->filearray as $key => $value) {
$ext = substr($value,(strpos($value, ".")+1));
$ext = strtolower($ext);
if(!in_array($ext, $extensions)){
unset($this->filearray[$key]);
}
}
}
}
class PageNavigator {
// общее число страниц, необходимых для вывода всего списка изображений
private $totalpages;
// число изображений на одной странице
private $recordsperpage;
// текущая страница
private $currentpage;
// текст для навигации
private $strfirst = '←';
private $strlast = '→';
public function __construct($totalrecords, $recordsperpage = 10, $currentpage = 1){
$this->totalrecords = $totalrecords;
$this->recordsperpage = $recordsperpage;
$this->currentpage = $currentpage;
$this->setTotalPages($totalrecords, $recordsperpage);
}
// Возвращает HTML код навигатора
public function getNavigator(){
$strnavigator = ' </div><div class="blok2"><div class="button">'."\n";
// Ссылка "Первая страница"
if($this->currentpage != 1) {
$strnavigator .= $this->createLink(1, $this->strfirst);
$strnavigator .= ' ';
}
// Две страницы назад + текущая страница + две страницы вперед
for($i = $this->currentpage - 3; $i <= $this->currentpage + 3; $i++) {
if($i < 1 or $i > $this->totalpages) continue;
if($i == $this->currentpage) {
$strnavigator .= '<b>';
$strnavigator .= $i;
$strnavigator .= '</b>'."\n";
} else {
$strnavigator .= $this->createLink($i, $i);
}
if ($i != $this->totalpages) $strnavigator .= ' ';
}
// Ссылка "Последняя страница"
if($this->currentpage != $this->totalpages){
$strnavigator .= ' ';
$strnavigator .= $this->createLink($this->totalpages, $this->strlast);
}
$strnavigator .= '</div>'."\n";
return $strnavigator;
}
private function createLink($offset, $strdisplay ){
$strtemp = '<a href="'.$_SERVER['PHP_SELF'].'?page='.$offset.'">'.$strdisplay.'</a>'."\n";
return $strtemp;
}
// всего страниц
private function setTotalPages($totalrecords, $recordsperpage){
$this->totalpages = ceil($totalrecords/$recordsperpage);
}
}
?>
<?php
ob_start();
$_SESSION['gen1'] = microtime(1);
foot();
?>
define( 'PERPAGE', 5 );
$directory = '123123';
$dir = new DirectoryItems($directory);
// Отфильтровываем все файлы, которые не являются изображениями
$dir->filter();
// Сортируем картинки
$dir->indexOrder = 'O = D';
// Общее количество изображений в директории
$totalCount = $dir->getCount();
// Текущая страница
if ( isset( $_GET['page'] ) )
$page = $_GET['page'];
else
$page = 1;
$numPages = ceil($totalCount/PERPAGE);
if ( $page < 1 ) $page = 1;
if ( $page > $numPages ) $page = $numPages;
// Получаем часть массива
$filearray = $dir->getFileArraySlice( ($page-1)*PERPAGE, PERPAGE);
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
foreach( $filearray as $value) {
$path = $dir->getDirectoryName().'/'.$value;
echo '<a href="download.php?image='.$path.'"><img src="download.php?image='.$path.'" alt="" /></a>'."\n";
}
// Создавать постраничную навигацию есть смысл, только если
// есть больше одной страницы
if($numPages > 1) {
// Создаем навигатор
$nav = new PageNavigator($totalCount, PERPAGE, $page);
echo $nav->getNavigator();
}
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.");
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.");
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
// исключить из массива все элементы с недопустимым расширением
public function filter(){
$extensions = array("jpg", "jpeg", "gif", "png");
foreach ($this->filearray as $key => $value) {
$ext = substr($value,(strpos($value, ".")+1));
$ext = strtolower($ext);
if(!in_array($ext, $extensions)){
unset($this->filearray[$key]);
}
}
}
}
class PageNavigator {
// общее число страниц, необходимых для вывода всего списка изображений
private $totalpages;
// число изображений на одной странице
private $recordsperpage;
// текущая страница
private $currentpage;
// текст для навигации
private $strfirst = '←';
private $strlast = '→';
public function __construct($totalrecords, $recordsperpage = 10, $currentpage = 1){
$this->totalrecords = $totalrecords;
$this->recordsperpage = $recordsperpage;
$this->currentpage = $currentpage;
$this->setTotalPages($totalrecords, $recordsperpage);
}
// Возвращает HTML код навигатора
public function getNavigator(){
$strnavigator = ' </div><div class="blok2"><div class="button">'."\n";
// Ссылка "Первая страница"
if($this->currentpage != 1) {
$strnavigator .= $this->createLink(1, $this->strfirst);
$strnavigator .= ' ';
}
// Две страницы назад + текущая страница + две страницы вперед
for($i = $this->currentpage - 3; $i <= $this->currentpage + 3; $i++) {
if($i < 1 or $i > $this->totalpages) continue;
if($i == $this->currentpage) {
$strnavigator .= '<b>';
$strnavigator .= $i;
$strnavigator .= '</b>'."\n";
} else {
$strnavigator .= $this->createLink($i, $i);
}
if ($i != $this->totalpages) $strnavigator .= ' ';
}
// Ссылка "Последняя страница"
if($this->currentpage != $this->totalpages){
$strnavigator .= ' ';
$strnavigator .= $this->createLink($this->totalpages, $this->strlast);
}
$strnavigator .= '</div>'."\n";
return $strnavigator;
}
private function createLink($offset, $strdisplay ){
$strtemp = '<a href="'.$_SERVER['PHP_SELF'].'?page='.$offset.'">'.$strdisplay.'</a>'."\n";
return $strtemp;
}
// всего страниц
private function setTotalPages($totalrecords, $recordsperpage){
$this->totalpages = ceil($totalrecords/$recordsperpage);
}
}
?>
<?php
ob_start();
$_SESSION['gen1'] = microtime(1);
foot();
?>
class DirectoryItems найди и кинь файлом сюда...
elfi, не грузит пишет Вы пытаетесь загрузить запрещенный тип файла
elfi, вот сам класс
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.";
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.";
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.";
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.";
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
pandasam (04.07.2015 в 15:50)
elfi, вот сам класс
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.";
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.";
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
elfi, вот сам класс
class DirectoryItems {
private $filearray = array();
private $directory;
public function __construct($directory) {
$this->directory = $directory;
if ( is_dir($directory) ) {
$d = opendir( $directory ) or die("Failed to open directory.";
while ( false !== ($f = readdir($d)) ) {
if( is_file($directory.'/'.$f) ) {
$this->filearray[] = $f;
}
}
closedir($d);
} else {
die("Must pass in a directory.";
}
}
public function __destruct(){
unset($this->filearray);
}
public function getDirectoryName(){
return $this->directory;
}
public function indexOrder(){
sort($this->filearray);
}
public function getCount() {
return count($this->filearray);
}
public function getFileArray() {
return $this->filearray;
}
public function getFileArraySlice($start, $numberitems) {
return array_slice($this->filearray, $start, $numberitems);
}
файл в зип запакуй и скинь сюда...
elfi, вот клвсс в zip'КЕ
pandasam, public function indexOrder(){
sort($this->filearray,SORT_NATURAL);
} попробуй так.
sort($this->filearray,SORT_NATURAL);
} попробуй так.
elfi, нет все так же я кидаю картинку а она как в папке стояла по счету так и выводиится
pandasam (04.07.2015 в 16:01)
elfi, нет все так же я кидаю картинку а она как в папке стояла по счету так и выводиится
elfi, нет все так же я кидаю картинку а она как в папке стояла по счету так и выводиится
http://php.net/manual/ru/function.sort.php тогда тут подбери себе нужный флаг сортировки...
elfi, я пытался но ему все п..
я кидаю картинку в папку а она в центре или вообще в конце
я кидаю картинку в папку а она в центре или вообще в конце