Модераторы: Aliance, skyboy, MoLeX, ksnk
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Рандомый вывод картинок, Помогите доделать скрипт 
:(
    Опции темы
PavelCh
Дата 19.11.2008, 14:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 14.9.2006

Репутация: нет
Всего: нет



Всем привет.

Пытаюсь доделать скрипт по рандомному выводу картинок, но я не силён в php, поэтому пока получается не очень.

Вот код оригинала:
Код

<?php
// запрет прямого доступа
defined( '_VALID_MOS' ) or die( 'Доступ ограничен' );

global $mosConfig_absolute_path, $mosConfig_live_site;

$type            = $params->get( 'type', 'jpg' );
$folder        = $params->get( 'folder' );
$link            = $params->get( 'link' );
$width            = $params->get( 'width' );
$height        = $params->get( 'height' );
$the_array        = array();
$the_image        = array();

// if folder includes livesite info, remove
if ( strpos($folder, $mosConfig_live_site) === 0 ) {
    $folder = str_replace( $mosConfig_live_site, '', $folder );
}
// if folder includes absolute path, remove
if ( strpos($folder, $mosConfig_absolute_path) === 0 ) {
    $folder= str_replace( $mosConfig_absolute_path, '', $folder );
}
// if folder doesnt contain slash to start, add
if ( strpos($folder, '/') !== 0 ) {    
    $folder = '/'. $folder;
}
// construct absolute path to directory
$abspath_folder = $mosConfig_absolute_path . $folder;
// check if directory exists
if (is_dir($abspath_folder)) {
    if ($handle = opendir($abspath_folder)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
                $the_array[] = $file;
            }
        }
    }
    closedir($handle);

    foreach ($the_array as $img) {
        if (!is_dir($abspath_folder .'/'. $img)) {
            if (eregi($type, $img)) {
                $the_image[] = $img;
            }
        }
    }

    if (!$the_image) {
        echo _NO_IMAGES;
    } else {

    $i = count($the_image);
    $random = mt_rand(0, $i - 1);
    $image_name = $the_image[$random];
        $abspath_image    = $abspath_folder . '/'. $image_name;
        $size            = getimagesize ($abspath_image);

    if ($width == '') {
            ($size[0] > 100 ? $width = 100 : $width = $size[0]);
    }
    if ($height == '') {
        $coeff = $size[0]/$size[1];
        $height = (int) ($width/$coeff);
    }

        $image = $mosConfig_live_site . $folder .'/'. $image_name;


    ?>
    <div align="center">
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" /><br />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div>
    <?php
    }
}
?>


В код был добавлен рандом и таблица(3 ячейки), в каждую ячейку скопипастил кусок вывода картинок:
Код

<?php
// запрет прямого доступа
defined( '_VALID_MOS' ) or die( 'Доступ ограничен' );

global $mosConfig_absolute_path, $mosConfig_live_site;

$type            = $params->get( 'type', 'jpg' );
$folder        = $params->get( 'folder' );
$link            = $params->get( 'link' );
$width            = $params->get( 'width' );
$height        = $params->get( 'height' );
$the_array        = array();
$the_image        = array();

// if folder includes livesite info, remove
if ( strpos($folder, $mosConfig_live_site) === 0 ) {
    $folder = str_replace( $mosConfig_live_site, '', $folder );
}
// if folder includes absolute path, remove
if ( strpos($folder, $mosConfig_absolute_path) === 0 ) {
    $folder= str_replace( $mosConfig_absolute_path, '', $folder );
}
// if folder doesnt contain slash to start, add
if ( strpos($folder, '/') !== 0 ) {    
    $folder = '/'. $folder;
}
// construct absolute path to directory
$abspath_folder = $mosConfig_absolute_path . $folder;
// check if directory exists
if (is_dir($abspath_folder)) {
    if ($handle = opendir($abspath_folder)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
                $the_array[] = $file;
            }
        }
    }
    closedir($handle);

    foreach ($the_array as $img) {
        if (!is_dir($abspath_folder .'/'. $img)) {
            if (eregi($type, $img)) {
                $the_image[] = $img;
            }
        }
    }

    if (!$the_image) {
        echo _NO_IMAGES;
    } else {

shuffle($the_image);
for($AAAA=0;$AAAA<3;$AAAA++) {

    $i = count($the_image);
    $random = $AAAA;
    $image_name = $the_image[$random];
        $abspath_image    = $abspath_folder . '/'. $image_name;
        $size            = getimagesize ($abspath_image);

    if ($width == '') {
            ($size[0] > 100 ? $width = 100 : $width = $size[0]);
    }
    if ($height == '') {
        $coeff = $size[0]/$size[1];
        $height = (int) ($width/$coeff);
    }

        $image = $mosConfig_live_site . $folder .'/'. $image_name;

    ?>
    
    <table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
  </tr>
</table>
    <?php
    }
}
}
?>

Проблема в том, что в каждой ячейки выводятся 3 одинаковые картинки, а мне нада сделать, чтобы выводились рандомно разные, подскажите, где чего дописать нада...?
PM MAIL   Вверх
PavelCh
Дата 21.11.2008, 15:58 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 14.9.2006

Репутация: нет
Всего: нет



Эх, жаль что никто подсказать не может...
PM MAIL   Вверх
teroni
Дата 21.11.2008, 16:36 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 381
Регистрация: 15.5.2007
Где: Днепропетровск

Репутация: 1
Всего: 22



Ну так а с чего картинкам разным быть, если вы 3 раза одну и ту же $image выводите?
Сделайте
Код

for ($AAAA=0; $AAAA<3; $AAAA++)
{
$image_name1 = $the_image[3*$AAAA];
$image_name2 = $the_image[3*$AAAA + 1];
$image_name3 = $the_image[3*$AAAA + 2];
// и тд, копируйте код, только делайте для разных картинок разные переменные.....
}


Это сообщение отредактировал(а) teroni - 21.11.2008, 16:37
PM MAIL   Вверх
PavelCh
Дата 18.12.2008, 18:28 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 14.9.2006

Репутация: нет
Всего: нет



Извиняюсь что так долго не отвечал, был в отъезде...

Сделал вот так:
Код

<?php

// запрет прямого доступа
defined( '_VALID_MOS' ) or die( 'Доступ ограничен' );

global $mosConfig_absolute_path, $mosConfig_live_site;

$type            = $params->get( 'type', 'jpg' );
$folder        = $params->get( 'folder' );
$link            = $params->get( 'link' );
$width            = $params->get( 'width' );
$height        = $params->get( 'height' );
$the_array        = array();
$the_image        = array();

// if folder includes livesite info, remove
if ( strpos($folder, $mosConfig_live_site) === 0 ) {
    $folder = str_replace( $mosConfig_live_site, '', $folder );
}
// if folder includes absolute path, remove
if ( strpos($folder, $mosConfig_absolute_path) === 0 ) {
    $folder= str_replace( $mosConfig_absolute_path, '', $folder );
}
// if folder doesnt contain slash to start, add
if ( strpos($folder, '/') !== 0 ) {    
    $folder = '/'. $folder;
}
// construct absolute path to directory
$abspath_folder = $mosConfig_absolute_path . $folder;
// check if directory exists
if (is_dir($abspath_folder)) {
    if ($handle = opendir($abspath_folder)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
                $the_array[] = $file;
            }
        }
    }
    closedir($handle);

    foreach ($the_array as $img) {
        if (!is_dir($abspath_folder .'/'. $img)) {
            if (eregi($type, $img)) {
                $the_image[] = $img;
            }
        }
    }

    if (!$the_image) {
        echo _NO_IMAGES;
    } else {


shuffle($the_image);
for($AAAA=0;$AAAA<3;$AAAA++)
{
$image_name1 = $the_image[3*$AAAA];
$image_name2 = $the_image[3*$AAAA + 1];
$image_name3 = $the_image[3*$AAAA + 2];}
{


    $i = count($the_image);
    $random = $AAAA;
    $image_name = $the_image[$random];
        $abspath_image    = $abspath_folder . '/'. $image_name;
        $size            = getimagesize ($abspath_image);

    if ($width == '') {
            ($size[0] > 100 ? $width = 100 : $width = $size[0]);
    }
    if ($height == '') {
        $coeff = $size[0]/$size[1];
        $height = (int) ($width/$coeff);
    }

        $image = $mosConfig_live_site . $folder .'/'. $image_name;


    ?>
    
    <table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image_name1; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image_name2; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
    <td><div>
    <?php
    if ($link) {
        ?>
        <a href="<?php echo $link; ?>" target="_self">
        <?php
    }
    ?>
    <img src="<?php echo $image_name3; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" />
    <?php
    if ($link) {
        ?>
        </a>
        <?php
    }
    ?>
    </div></td>
  </tr>
</table>

    
    <?php
    }
}
}
?>

Не работает, даже картинки не выводит, только 3 рамки.

Это сообщение отредактировал(а) PavelCh - 18.12.2008, 18:28
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | PHP: Графика | Следующая тема »


 




[ Время генерации скрипта: 0.0774 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.