Pornocat
Новичок
Помогите в чем ошибка не пойму???
Есть код выводящий 10 случайных предосмотров из подпапок основной папки img
Проблема в том что 10 предосмотров он не выводит а 5 или 6 по разному а хотелось чтобы все 10!!!
<?php
//Îáùàÿ äèðåêòîðèÿ èçîáðàæåíèé
define ("_IMG_root", "img" );
function img_resize($src, $dest, $width, $height, $rgb = 0xFFFFFF, $quality = 100) {
if (!file_exists($src)) return false;
$size = getimagesize($src);
if ($size === false) return false;
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc)) return false;
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
$ratio = min ($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
$isrc = $icfunc($src);
$idest = imagecreatetruecolor ($width, $height );
imagefill ($idest, 0, 0, $rgb );
imagecopyresampled ($idest, $isrc, $new_left, $new_top, 0, 0,
$new_width, $new_height, $size[0], $size[1]);
imagejpeg ($idest, $dest, $quality );
imagedestroy ($isrc );
imagedestroy ($idest );
return true;
}
$Open_temp = opendir ("temp");
while ($Read_temp = readdir ($Open_temp)) {
if ($Read_temp == "." ) { continue; }
if ($Read_temp == ".." ) { continue; }
$NEW_TEMP[] = $Read_temp;
}
$Open_scan = opendir (_IMG_root);
for ($xx = 0; $xx < count ($NEW_TEMP); $xx++) {
//Äèðåêòîðèè èçîáðàæåíèé
while ($Read_scan = readdir ($Open_scan)) {
if (filetype (_IMG_root."/".$Read_scan) === "dir") {
if ($Read_scan == "." ) { continue; }
if ($Read_scan == "..") { continue; }
$Scan_element[] = $Read_scan;
}
}
$Count_scan_array = count ($Scan_element );
$R_e_l_path = rand (0, $Count_scan_array -1);
//Ãåíåðèðóåì ñëó÷àéíóþ äèðåêòîðèþ
$Open_path_img = opendir (_IMG_root."/".$Scan_element[$R_e_l_path]);
while ($Read_element = readdir ($Open_path_img)) {
$Image_array[] = $Read_element;
}
for ($x = 0; $x < count ($Image_array); $x++) {
if ($Image_array[$x] == "." ) { continue; }
if ($Image_array[$x] == ".." ) { continue; }
if ($Image_array[$x] == "index.html") { continue; }
if ($Image_array[$x] == "index.htm" ) { continue; }
// ñëó÷àå åñëè windows õîñòèíã
if ($Image_array[$x] == "Thumbs.db" ) { continue; }
$Convert[] = $Image_array[$x];
$Check = count ($Convert);
}
if (!empty ($Check)) {
//Ïîä÷èòûâàåì êîëè÷åñòâî ýëåìåíòîâ ìàññèâà
$Img_array_count = count ($Convert );
$Rand_image = rand (0, $Img_array_count -1);
//Ãåíåðèðóåì ïðîèçâîëüíóþ êàðòèíêó
$Select_element = $Convert[$Rand_image];
$RANOM[] = $Convert[$Rand_image];
$DEARRAY = implode ("-", $RANOM);
if (substr_count ($DEARRAY, $Select_element) > 1) { continue; }
if (img_resize(_IMG_root."/".$Scan_element[$R_e_l_path]."/".$Select_element, "temp/".md5 ("$Select_element").".jpg", 150, 150)) {
print "<a href = "._IMG_root."/".$Scan_element[$R_e_l_path]."/".$Select_element."><img src = \"temp/".md5 ("$Select_element").".jpg"."\" /></a>";
} else {
}
} else {
echo "Íåò èçîáðàæåíèÿ!";
}
if ($xx > 9) { break; }
}
?>
Есть код выводящий 10 случайных предосмотров из подпапок основной папки img
Проблема в том что 10 предосмотров он не выводит а 5 или 6 по разному а хотелось чтобы все 10!!!
<?php
//Îáùàÿ äèðåêòîðèÿ èçîáðàæåíèé
define ("_IMG_root", "img" );
function img_resize($src, $dest, $width, $height, $rgb = 0xFFFFFF, $quality = 100) {
if (!file_exists($src)) return false;
$size = getimagesize($src);
if ($size === false) return false;
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc)) return false;
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
$ratio = min ($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
$isrc = $icfunc($src);
$idest = imagecreatetruecolor ($width, $height );
imagefill ($idest, 0, 0, $rgb );
imagecopyresampled ($idest, $isrc, $new_left, $new_top, 0, 0,
$new_width, $new_height, $size[0], $size[1]);
imagejpeg ($idest, $dest, $quality );
imagedestroy ($isrc );
imagedestroy ($idest );
return true;
}
$Open_temp = opendir ("temp");
while ($Read_temp = readdir ($Open_temp)) {
if ($Read_temp == "." ) { continue; }
if ($Read_temp == ".." ) { continue; }
$NEW_TEMP[] = $Read_temp;
}
$Open_scan = opendir (_IMG_root);
for ($xx = 0; $xx < count ($NEW_TEMP); $xx++) {
//Äèðåêòîðèè èçîáðàæåíèé
while ($Read_scan = readdir ($Open_scan)) {
if (filetype (_IMG_root."/".$Read_scan) === "dir") {
if ($Read_scan == "." ) { continue; }
if ($Read_scan == "..") { continue; }
$Scan_element[] = $Read_scan;
}
}
$Count_scan_array = count ($Scan_element );
$R_e_l_path = rand (0, $Count_scan_array -1);
//Ãåíåðèðóåì ñëó÷àéíóþ äèðåêòîðèþ
$Open_path_img = opendir (_IMG_root."/".$Scan_element[$R_e_l_path]);
while ($Read_element = readdir ($Open_path_img)) {
$Image_array[] = $Read_element;
}
for ($x = 0; $x < count ($Image_array); $x++) {
if ($Image_array[$x] == "." ) { continue; }
if ($Image_array[$x] == ".." ) { continue; }
if ($Image_array[$x] == "index.html") { continue; }
if ($Image_array[$x] == "index.htm" ) { continue; }
// ñëó÷àå åñëè windows õîñòèíã
if ($Image_array[$x] == "Thumbs.db" ) { continue; }
$Convert[] = $Image_array[$x];
$Check = count ($Convert);
}
if (!empty ($Check)) {
//Ïîä÷èòûâàåì êîëè÷åñòâî ýëåìåíòîâ ìàññèâà
$Img_array_count = count ($Convert );
$Rand_image = rand (0, $Img_array_count -1);
//Ãåíåðèðóåì ïðîèçâîëüíóþ êàðòèíêó
$Select_element = $Convert[$Rand_image];
$RANOM[] = $Convert[$Rand_image];
$DEARRAY = implode ("-", $RANOM);
if (substr_count ($DEARRAY, $Select_element) > 1) { continue; }
if (img_resize(_IMG_root."/".$Scan_element[$R_e_l_path]."/".$Select_element, "temp/".md5 ("$Select_element").".jpg", 150, 150)) {
print "<a href = "._IMG_root."/".$Scan_element[$R_e_l_path]."/".$Select_element."><img src = \"temp/".md5 ("$Select_element").".jpg"."\" /></a>";
} else {
}
} else {
echo "Íåò èçîáðàæåíèÿ!";
}
if ($xx > 9) { break; }
}
?>