Jojee
08-06-2008, 07:36 AM
I don't get PHP at all. Here's my code:
<?php
$catdir = 'avatars_icons';
$sort = 'first';
$getcount = true;
$perpage = 20;
$divider = ' | ';
if (!file_exists($catdir)) {
exit();
}
$getfolders = opendir($catdir);
while (($file = readdir($getfolders)) !== false) {
if (($file != '.' && $file != '..') && (is_dir($catdir.'/'.$file))) {
$cats[] = $file;
}
}
if (!$cats) {
exit();
}
natcasesort($cats);
if ((!$_GET['cat']) || (!in_array($_GET['cat'], $cats))) {
?>
<?php
foreach ($cats as $value) {
$catname = str_replace('_', ' ', $value);
echo '<a href="' . $_SERVER['PHP_SELF'] . '?cat=' . $value . '">';
<b> echo '<img src=avatars_icons/ . $value . /icon.png></a>';</b>
if ($getcount) {
$icons = array();
$getcount = opendir($catdir . '/' . $value);
while (($icon = readdir($getcount)) !== false) {
if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
$icons[] = $value;
}
}
$count = count($icons);
if ($count == 1) {
echo ' (' . $count . ' icon)';
} else {
echo ' (' . $count . ' icons)';
}
}
}
}
ETC IT GOES ON.
Okay, so basically this is an avatar gallery script. You make folders in a specified directory ($catdir), it displays the name of the folders inside that directory and how many avatars are inside, and when you click the link it displays those avatars.
Where I'm having trouble is still in the very beginning - displaying the categories. Something's wrong with the bolded part of the script. If I put simple text in there, it works fine, but when I try to add the image, nothing displays. It has to do with $value, because when I put in the folder name straight out, it does work. Is $value the wrong variable to use in this case, or am I just doing something wrong? I'm trying to go to each folder in the directory, pull out the image inside the folder called icon.png, and display that image.
Do you know what I'm trying to get at? ~_~
Thanks in advance to anyone who can help.
<?php
$catdir = 'avatars_icons';
$sort = 'first';
$getcount = true;
$perpage = 20;
$divider = ' | ';
if (!file_exists($catdir)) {
exit();
}
$getfolders = opendir($catdir);
while (($file = readdir($getfolders)) !== false) {
if (($file != '.' && $file != '..') && (is_dir($catdir.'/'.$file))) {
$cats[] = $file;
}
}
if (!$cats) {
exit();
}
natcasesort($cats);
if ((!$_GET['cat']) || (!in_array($_GET['cat'], $cats))) {
?>
<?php
foreach ($cats as $value) {
$catname = str_replace('_', ' ', $value);
echo '<a href="' . $_SERVER['PHP_SELF'] . '?cat=' . $value . '">';
<b> echo '<img src=avatars_icons/ . $value . /icon.png></a>';</b>
if ($getcount) {
$icons = array();
$getcount = opendir($catdir . '/' . $value);
while (($icon = readdir($getcount)) !== false) {
if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
$icons[] = $value;
}
}
$count = count($icons);
if ($count == 1) {
echo ' (' . $count . ' icon)';
} else {
echo ' (' . $count . ' icons)';
}
}
}
}
ETC IT GOES ON.
Okay, so basically this is an avatar gallery script. You make folders in a specified directory ($catdir), it displays the name of the folders inside that directory and how many avatars are inside, and when you click the link it displays those avatars.
Where I'm having trouble is still in the very beginning - displaying the categories. Something's wrong with the bolded part of the script. If I put simple text in there, it works fine, but when I try to add the image, nothing displays. It has to do with $value, because when I put in the folder name straight out, it does work. Is $value the wrong variable to use in this case, or am I just doing something wrong? I'm trying to go to each folder in the directory, pull out the image inside the folder called icon.png, and display that image.
Do you know what I'm trying to get at? ~_~
Thanks in advance to anyone who can help.