Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ПУТЬ к папке с изображениями ОТНОСИТЕЛЬНЫЙ
- $imgDir = 'assets/gallery/';
- // ИМЯ папки с превьюшками
- //(должна находиться внутри папки с изображениями):
- $thumbDir = 'assets/gallery/thumbs/';
- $pattern = "<img u='image' src='{0}'/> <img u='thumb' src='{1}'/>";
- $thumb_pattern = "{0}";
- // Получает файлы, расположенные в директории
- // @param $path : String - путь к директории с файлами,
- // return Array - индексный массив, содержащий файлы
- function getFiles(/*string*/$path)
- {
- // результат выполнения функции is_dir кэшируется,
- // поэтому сбрасываем кэш.
- clearstatcache();
- $files = scandir($path);
- for($i = 0, $length = count($files); $i < $length; $i++)
- {
- // Исключаем из списка директории:
- if( is_dir($path.$files[$i]) )
- {
- unset($files[$i]);
- }
- }
- return array_slice($files,2); //array
- }
- $pairs = [];
- $images = getFiles($imgDir);
- foreach($images as $big_picture) {
- $first_step_pattern = str_replace("{0}",$imgDir.$big_picture,$pattern);
- $second_pattern = str_replace("{0}", $big_picture, $thumb_pattern);
- if (file_exists($thumbDir.$second_pattern))
- $pairs[$big_picture] = str_replace("{1}",$thumbDir.$second_pattern, $first_step_pattern);
- else
- print_r($second_pattern." doesn't exist!!!");
- }
- //$pairs - тут уже будет лежать готовый html код, в который из шаблона $pattern вставяется вместо {0} и {1} основная и мелкая картинки с их урлами
- print_r($pairs);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement