okay, so i've made a script to display all the images in a directory hosted here on my server (<!-- m --><a class="postlink" href="http://24.238.145.39/morrowasted/v9/skate/kee.php">http://24.238.145.39/morrowasted/v9/skate/kee.php</a><!-- m -->) .
it displays a crapload of smileys, as you can see.
some of these are animated, which brings me to my point... when you have a couple hundred animated gif smileys on your page, they tend to be... slow...
so, i'd like to make it so that it only displays a certain number per page, kind of like on this forum, the posts per page option.
this is the script i am using:
<?php
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
?>
how can i do this?anybody ?Many different ways. One is to pass a variable from page to page and use a url like smilies.php?page=001 to call it.
Read all of the filenames into the array, but when showing the images only show 1 to 10 if page = 001 and only show 11 to 20 if page = 002 and so on.
There are many other ways of doing this, but that might be the easiest. You'll need the GET command to access the page value from the passed URL.hm, never thought of that.
thanks for the advice.There are a shed load of PHP Image Gallery Scripts out there if you look using Google.umm very difficult if you overwrite the array everytime you load the page.
doing it the way you are is almost impossible to do. you would have to get all of them in the array and keep them there and then when the page loads it will not overwrite that array. actually you can do what you are doing but you can't echo the image where you are. load it all in the array there and then get the value from the url and do a for--loop on the array according to the number in the url.
<?php
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$img[] = $file;
//echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
$total = count($img);
for ($i=0; $i<$_GET['page']; $i++){
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/img[$i]\">";
}
?>
actually that will show so many and you can't continue on unless you lost all of them but should give you an idea.thanks scoutt.
with that code, how would i control the number to display per page?are you sure that works right, scoutt? i didnt test it, but it looked like it didnt...
heres greg, works perfectly
$img = array();
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$img[] = $file;
//echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
$perPage = 10; //how many images per page
$page = isset($_GET['p'])?$_GET['p']:1; //checks to see if the page variable is set
if( $page < 1 ) { //checks if page is less than 1
$page = 1;
} else if ( $page > ceil(sizeof($img)/$perPage) ) { //checks if page is too high
$page = ceil(sizeof($img)/$perPage);
}
for( $num = (($page-1)*$perPage); $num < (($page-1)*$perPage+$perPage); $num++ ) {
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/". $img[$num] ."\">";
}
the variable in the URL will be ?p=somenumber
you can add previous and next links really easily. just have it echo a url where p = p-1 and p+1, but you also need to add in some checking. so if p-1 < 1 then dont have the previous link, and if p+1 > ceil(sizeof($img)/$perPage) then dont have a next linkI never tested it either, just wrote it off the top of my head.
it was just an exmple anyway to get him started.yeah, because it always starts at 0. it doesnt increment in blocks. it only adds more to the output and I also said it will get him started. I refuse to write the whole code.yeah well no he uhh sa--SHUTUP!
*cries*thanks nate, works perfect!
i even understand how it worksYeah, I agree with Scoutt on this one.
I don't like to write the whole thing, but rather just give some clues and a short sample to get someone started. they will learn more by finishing it for themselves.
Besides, htmlfoums isn't a help desk!Besides, htmlfoums isn't a help desk!
exactly why i skipped over them and came straight herebut its Gregory!
he was just going to ask me to do it for him sooner or later on AIM, so i might as well jsut post it XDXDXDXD
(gregory: im kidding, so dont take it personally, not that you would >_>)its true its true, nate is atthe top of my buddy list.
whenever i have a problem, i just click on "naffee son" and boom its fixed.
perhaps thats why my questions on here have been declining
it displays a crapload of smileys, as you can see.
some of these are animated, which brings me to my point... when you have a couple hundred animated gif smileys on your page, they tend to be... slow...
so, i'd like to make it so that it only displays a certain number per page, kind of like on this forum, the posts per page option.
this is the script i am using:
<?php
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
?>
how can i do this?anybody ?Many different ways. One is to pass a variable from page to page and use a url like smilies.php?page=001 to call it.
Read all of the filenames into the array, but when showing the images only show 1 to 10 if page = 001 and only show 11 to 20 if page = 002 and so on.
There are many other ways of doing this, but that might be the easiest. You'll need the GET command to access the page value from the passed URL.hm, never thought of that.
thanks for the advice.There are a shed load of PHP Image Gallery Scripts out there if you look using Google.umm very difficult if you overwrite the array everytime you load the page.
doing it the way you are is almost impossible to do. you would have to get all of them in the array and keep them there and then when the page loads it will not overwrite that array. actually you can do what you are doing but you can't echo the image where you are. load it all in the array there and then get the value from the url and do a for--loop on the array according to the number in the url.
<?php
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$img[] = $file;
//echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
$total = count($img);
for ($i=0; $i<$_GET['page']; $i++){
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/img[$i]\">";
}
?>
actually that will show so many and you can't continue on unless you lost all of them but should give you an idea.thanks scoutt.
with that code, how would i control the number to display per page?are you sure that works right, scoutt? i didnt test it, but it looked like it didnt...
heres greg, works perfectly
$img = array();
$dir = "smilies";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$img[] = $file;
//echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}
$perPage = 10; //how many images per page
$page = isset($_GET['p'])?$_GET['p']:1; //checks to see if the page variable is set
if( $page < 1 ) { //checks if page is less than 1
$page = 1;
} else if ( $page > ceil(sizeof($img)/$perPage) ) { //checks if page is too high
$page = ceil(sizeof($img)/$perPage);
}
for( $num = (($page-1)*$perPage); $num < (($page-1)*$perPage+$perPage); $num++ ) {
echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/". $img[$num] ."\">";
}
the variable in the URL will be ?p=somenumber
you can add previous and next links really easily. just have it echo a url where p = p-1 and p+1, but you also need to add in some checking. so if p-1 < 1 then dont have the previous link, and if p+1 > ceil(sizeof($img)/$perPage) then dont have a next linkI never tested it either, just wrote it off the top of my head.
it was just an exmple anyway to get him started.yeah, because it always starts at 0. it doesnt increment in blocks. it only adds more to the output and I also said it will get him started. I refuse to write the whole code.yeah well no he uhh sa--SHUTUP!
*cries*thanks nate, works perfect!
i even understand how it worksYeah, I agree with Scoutt on this one.
I don't like to write the whole thing, but rather just give some clues and a short sample to get someone started. they will learn more by finishing it for themselves.
Besides, htmlfoums isn't a help desk!Besides, htmlfoums isn't a help desk!
exactly why i skipped over them and came straight herebut its Gregory!
he was just going to ask me to do it for him sooner or later on AIM, so i might as well jsut post it XDXDXDXD
(gregory: im kidding, so dont take it personally, not that you would >_>)its true its true, nate is atthe top of my buddy list.
whenever i have a problem, i just click on "naffee son" and boom its fixed.
perhaps thats why my questions on here have been declining