Click to See Complete Forum and Search --> : display certain contents of a directory.


cybercampbell
08-23-2004, 01:26 PM
Hi all I'm using this script to display the contents of a directory....well in my case it's jpg's.


// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
...
while ($file = readdir($dir_handle)) {

if($file == "." || $file == ".." || $file == "view.dir.php" )

continue;
echo "
<img src=\"$file\">
<br>
$file
";

// Close
closedir($dir_handle);


I'm wanting to modify it to display either the first 6 jpg's or the next 6 and then the next 6 and so on and so on.

and I would like this to be set by a variable which is set by me..maybe something like this:


$select = 1to6
or
$select = 7to13
or
$select = 14to20


Any ideas would be much appreciated.

Cheers
Chris

96turnerri
08-25-2004, 03:23 AM
try something like


//Variables
$num1 = $_GET["num1"]; //or set default
$num2 = $_GET["num2"]; //or set default

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2) {

if($file == "." || $file == ".." || $file == "view.dir.php" ) {
echo "<img src=\"$file\"><br>$file";
$num++;
}

}

// Close
closedir($dir_handle);

cybercampbell
09-01-2004, 03:09 AM
Thanks for that.

I have been away and just got back.

I'm a bit unsure how it works.....would it be possible to get you to write a description of what the new code is doing.

Cheers
Chris

sciguyryan
09-01-2004, 06:38 AM
Originally posted by cybercampbell
Thanks for that.

I have been away and just got back.

I'm a bit unsure how it works.....would it be possible to get you to write a description of what the new code is doing.

Cheers
Chris

Here is a description for you:


<?php
//Variables
$num1 = $_GET["num1"]; //or set default
$num2 = $_GET["num2"]; //or set default

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file == "." || $file == ".." || $file == "view.dir.php" ){
echo "<img src=\"$file\"><br>$file";
$num++; // Incriment number ($numb = $numb +1)
}
}
// Close
closedir($dir_handle);
?>


Only two things seem to be changed.


RyanJ

96turnerri
09-01-2004, 07:03 AM
Originally posted by sciguyryan
Here is a description for you:


<?php
//Variables
$num1 = $_GET["num1"]; //or set default
$num2 = $_GET["num2"]; //or set default

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file == "." || $file == ".." || $file == "view.dir.php" ){
echo "<img src=\"$file\"><br>$file";
$num++; // Incriment number ($numb = $numb +1)
}
}
// Close
closedir($dir_handle);
?>


Only two things seem to be changed.


RyanJ

correct

cybercampbell
09-05-2004, 05:17 AM
OK this is where i'm at......

I have the following but It make little scence to me and doesn't work.
I know.... I know.... I'm frustrating! but I am trying to learn and have found the best way is to ask questions and see the results.

Can I be as rude to ask for some more help?

This is what is in my directory:
Index of /gallery
* Parent Directory
* picture_1.jpg
* picture_2.jpg
* picture_3.jpg
* picture_4.jpg
* picture_5.jpg
* picture_6.jpg
* picture_7.jpg
* picture_8.jpg
* picture_9.jpg
* picture_10.jpg
* picture_11.jpg
* picture_12.jpg
* picture_13.jpg
* picture_14.jpg
* picture_15.jpg
* picture_16.jpg
* picture_17.jpg
* picture_18.jpg

and in my php code are the tables I'd like to show the .jpgs in.

but I only want to show 6 jpgs at a time and then have a link "Back" & "Next" that will change the variable to tell the script to load in the next 6 jpgs or the previouse jpgs.

here is the whole script i'm using:

<?php
//Variables
$num1 = $_GET["num1"]; //or set default
$num2 = $_GET["num2"]; //or set default

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file == "." || $file == ".." || $file == "gallery.php" ){
echo <<<HED
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"></div> <div align="center"><img src="images/spacer.gif" width="100" height="10"></div> <div align="center"></div> <div align="center"></div> <div align="center"></div></td>
</tr>
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"></div> <div align="center"></div> <div align="center"></div> <div align="center"></div> <div align="center"><img src="images/spacer.gif" width="100" height="10"></div></td>
</tr>
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"><img src="images/spacer.gif" width="100" height="20"></div></td>
</tr>
<tr>
<td colspan="5"><div align="center">&lt;&lt; back | next &gt;&gt;</div></td>
</tr>
</table>
HED;
$num++; // Incriment number ($numb = $numb +1)
}
}

// Close
closedir($dir_handle);
?>


the "Back" & "Next" would be the links that set the Variables.

I hope I'm not asking to much...I think that i'm close.

Cheers
Chris

96turnerri
09-05-2004, 05:25 AM
try this

change

$num1 = $_GET["num1"]; //or set default
$num2 = $_GET["num2"]; //or set default


to


if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}


and change
back | next

to


$num3 = $num1-6;
if($num3 < 1) {
$num3 = 1;
}
$num4 = $num2-6;
if($num4 < 6) {
$num4 = 6;
}
$num5 = $num1+6;
$num6 = $num2+6;
<a href="?num1=$num3&num2=$num4">back</a> | <a href?num1=$num5&num2=$num6">next</a>

cybercampbell
09-05-2004, 05:33 AM
Thanks mate...I'll try it now.

should this line:

<a href="?num1=$num3&num2=$num4">back</a> | <a href?num1=$num5&num2=$num6">next</a>

be:

<a href="?num1=$num3&num2=$num4">back</a> | <a href="?num1=$num5&num2=$num6">next</a>

96turnerri
09-05-2004, 05:36 AM
yeah ooops sorry thats what you get for coding on sunday morning ;)

cybercampbell
09-05-2004, 05:44 AM
I'm just getting a blank screen.

aaaahhhhhhh!!!!!!....and ideas?

also can I set the default (as in no variable set ) to be the first 6?

Thanks for all your help
Chris

96turnerri
09-05-2004, 05:45 AM
thats what this does


if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}


could you post your ENTIRE code again, thanks

cybercampbell
09-05-2004, 05:48 AM
No Problem...thanks.

here it is:


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file == "." || $file == ".." || $file == "gallery.php" ){
echo <<<HED
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"></div> <div align="center"><img src="images/spacer.gif" width="100" height="10"></div> <div align="center"></div> <div align="center"></div> <div align="center"></div></td>
</tr>
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"></div> <div align="center"></div> <div align="center"></div> <div align="center"></div> <div align="center"><img src="images/spacer.gif" width="100" height="10"></div></td>
</tr>
<tr>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><img src="$file" width="100" height="100"></div></td>
</tr>
<tr>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
<td><div align="center"></div></td>
<td><div align="center">$file</div></td>
</tr>
<tr>
<td colspan="5"><div align="center"><img src="images/spacer.gif" width="100" height="20"></div></td>
</tr>
<tr>
<td colspan="5"><div align="center">&lt;&lt;
$num3 = $num1-6;
if($num3 < 1) {
$num3 = 1;
}
$num4 = $num2-6;
if($num4 < 6) {
$num4 = 6;
}
$num5 = $num1+6;
$num6 = $num2+6;
<a href="?num1=$num3&num2=$num4">back</a> | <a href="?num1=$num5&num2=$num6">next</a>
&gt;&gt;</div></td>
</tr>
</table>
HED;
$num++; // Incriment number ($numb = $numb +1)
}
}

// Close
closedir($dir_handle);
?>


do I need this line: $file == "gallery.php" ?

Cheers
Chris

96turnerri
09-05-2004, 05:53 AM
im a little concerned with this line

if($file == "." || $file == ".." || $file == "gallery.php" ){

i think it should be

if($file != "." || $file != ".." || $file != "gallery.php" ){

if that fails remove it and remove
} at bottom too

cybercampbell
09-05-2004, 05:57 AM
No change.....still a blank screen.

I think that line was to stop it from displaying the the parent directorys or soomething.

Chris

cybercampbell
09-05-2004, 05:59 AM
also is it posible to have it anly get and display .jpg extention and nothing else?

Cheers
Chris

96turnerri
09-05-2004, 06:03 AM
well yes it is
but

if($file == "." || $file == ".." || $file == "gallery.php" ){

is saying is the file is current directory, parent directory or gallery.php do this (ie print table etc)
whereas

if($file != "." || $file != ".." || $file != "gallery.php" ){

is saying if it is not any of the above do this (print table), that was my concern

ok, add

$num = 0;

just below

$dir_handle = @opendir($path) or die("Unable to open $path");


you have your table set up for 6 images, but they are all for the same one $file,

what you need to if is loop it like

<table>
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
</table>

that will echo a table 2x6 which is what you want, something like the above but custom for you, do you see what i mean?

sciguyryan
09-05-2004, 06:07 AM
Originally posted by cybercampbell
also is it posible to have it anly get and display .jpg extention and nothing else?

Cheers
Chris


Well, to display onyl .jpg files then you'll have to do something like:


<?php
$File = explode('.', $File);
$Extension = $File[1];
if ($Extension == "jpg"){
echo "<img src='" . $Dirctory . $File[0] . $File[1] "' />";
}
?>



RyanJ

cybercampbell
09-05-2004, 06:29 AM
Still a blank screen

this is the php I have now....have I stuffed up somwhere?


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 0;
// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
echo '
<table>
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
</table>
';
}
}

// Close
closedir($dir_handle);
?>

sciguyryan
09-05-2004, 06:43 AM
Yes, this bit:


echo '
<table>
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
</table>
';


Should be:


echo '<table>;
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
echo '</table>';


Hope that helps,

RyanJ

cybercampbell
09-05-2004, 06:48 AM
that put all the colours out and gave me errors.

sciguyryan
09-05-2004, 07:04 AM
Sorry, my bad, change what I gave you to this: (I missed out a ')


echo '<table>';
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
echo '</table>';

cybercampbell
09-05-2004, 07:17 AM
Still just a blenk screen

here is what I have now:


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 0;
// Loop through the files
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
echo '<table>';
$num = 1;
while($num <= 6) {
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
echo '</table>';
}
}

// Close
closedir($dir_handle);
?>


Any other ideas......can anyone else try thiis and see if it works.

Cheers
Chris

cybercampbell
09-05-2004, 07:18 AM
how would I incorperate the...

$Extension == "jpg"

stuff into this script?

Cheers
Chris

sciguyryan
09-05-2004, 07:30 AM
This code I ade a while ago is a little different to yours but, it does display all files with a specisic extension:


<?php
$Dir = "../Temporary/";
$Type = "jpg";
$Type = "." . $Type;
$Handle = @opendir($Dir);
while (false !== ($File = readdir($Handle))){
if (($File != ".") && ($File != "..")){
$File = explode(".", $File);
$FileN = $File[0];
$FileE = "." . $File[1];
if ($FileE == "$Type"){
echo "$Type file found: [" . $FileN . $FileE . "]<br />";
}
}
}
closedir($Handle);
?>


Demo: http://chatzone.viperhosting.net/Temporary/index.php?Page=List-Types

And it should be easy to modify into what you need.

RyanJ

Da Warriah
09-05-2004, 07:35 AM
Well you've got your conditions for the loop set up as $num >= $num1 && $num < $num2. But right before, you've set $num as 0. Assuming $num1 is at its default value, 0 is not greater than or equal to 1. Try this:

<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 1;
// Loop through the files
echo '<table>';
while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == "jpg" || $extension == "jpeg"){
echo "<tr><td>$num</td><td><img src=$num></td></tr>";
$num++;
}
}
}
echo '</table>';

// Close
closedir($dir_handle);
?>

This also incorporates the .jpg extension.

Edit: What I've done with the extension script is slightly different - I count up the elements in the array formed by exploding by '.', and then take the last one. This accounts for files like this.picture.jpg

cybercampbell
09-05-2004, 07:43 AM
still a blank screen.

when I look at the source all there is is:

<table></table>

I'm going craxy!!!

Chris

Does the php script have to be in the same directory as the jpgs? ...because it isn't.

sciguyryan
09-05-2004, 07:46 AM
Originally posted by cybercampbell
still a blank screen.

when I look at the source all there is is:

<table></table>

I'm going craxy!!!

Chris

Does the php script have to be in the same directory as the jpgs? ...because it isn't.


No, you would not need to because you have a variable to specify the directory.

RyanJ

sciguyryan
09-05-2004, 07:54 AM
Hmm, tried this on myserver and the error seems to be on this line:


while ($file = readdir($dir_handle) && $num >= $num1 && $num < $num2){ // Check the numbers from the


Try changing it too:


while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num <= $num2)){ // Check the numbers from the



RyanJ

cybercampbell
09-05-2004, 08:04 AM
OK!!! now i'm seeing something.

But not my jpgs ...just empty boxes.

any ideas

sciguyryan
09-05-2004, 08:20 AM
Yup, I can solve that too :)

Change this line:


echo "<tr><td>$num</td><td><img src=$num></td></tr>";


To this:


echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $pieces[1] . "'></td></tr>";



Hope that helps,

RyanJ

cybercampbell
09-05-2004, 08:31 AM
still the same...

here is what I have now:

<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "/www/m/me/htdocs/gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 1;
// Loop through the files
echo '<table>';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == "jpg"){
echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $pieces[1] . "'></td></tr>";
$num++;
}
}
}
echo '</table>';

// Close
closedir($dir_handle);
?>



And the last thing is that I would like it to echo the jpgs in a t able in a certain way...

i.e.
3 across and 2 down with then name of the jpg directly under the image.

Is this posible?

Cheers
Chris

Joy Joy Joy ....I feel like I'm getting somwhere.

sciguyryan
09-05-2004, 08:45 AM
Below is an exact copy of what I used here: http://chatzone.viperhosting.net/Temporary/Test5.php


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "Images/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 1;
// Loop through the files
echo '<table>';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == "gif"){
echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "'><br />" . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "</td></tr>";
$num++;
}
}
}
echo '</table>';

// Close
closedir($dir_handle);
?>


I think it maybe your location... Images are HTML and so, work off a url like: ../Images/Test.gif or http://www.home.com/gif.gif
Not like: /www/m/me/htdocs/gallery/gif.gif


Try changing it using ../ to go down a folder :)

I've added the feature you requested also :)

RyanJ

cybercampbell
09-05-2004, 08:57 AM
Thank you so much for you help...

I have changed the path to:

//Path
$path = "gallery/";

because the jpgs are in a folder called gallery witch is in the same directory as the gallery.php script i;m woring on.

does that sound correct?

But I'm now back to a blank screen.

Ahhhhhh!

Help!!!

Chris

sciguyryan
09-05-2004, 09:02 AM
I don't understand... Is the script in the same directory as the folder gallery or is it in a different folder such as a folder in the level below it?


RyanJ

cybercampbell
09-05-2004, 09:08 AM
Sorry mate

In my htdocs directory I have:
gallery.php
and
gallery (folder)

in the gallery folder I have 18 jpgs.
picture_1.jpg
picture_2.jpg
picture_3.jpg
picture_4.jpg
picture_5.jpg
picture_6.jpg
picture_7.jpg
picture_8.jpg
picture_9.jpg
picture_10.jpg
picture_11.jpg
picture_12.jpg
picture_13.jpg
picture_14.jpg
picture_15.jpg
picture_16.jpg
picture_17.jpg
picture_18.jpg

Cheers
Chris

sciguyryan
09-05-2004, 09:14 AM
In that case try this:

../gallery/


Hope that works but if not can I have a link to the page so, I can see the result?

Thanks RyanJ

cybercampbell
09-05-2004, 09:36 AM
that returned

Unable to open ../gallery/

which means it didn't find the directory.

It obviously found it ok before because I didn't get the error.

I'm using Firfox and the result is:

<table></table>

and that's it.

sciguyryan
09-05-2004, 09:49 AM
Well, I'm out of ideas :( change it back to the one you said earlier (gallery/) and then can you post the results from the pages source here?



RyanJ

cybercampbell
09-05-2004, 10:00 AM
Well arn't I lucky you're not here to kick me!!!!

The extention code that was added about 4 or 5 posts ago was for .gif not .jpg

fixed and works.

BUT......

it still shows them one beneth the other.
is ther a way to make them show 3 across and 2 down in a table?

Cheers
Chris

sciguyryan
09-05-2004, 10:04 AM
Glad that works :)

Anyway, what do you mean y 3 accross and two down? Can you be more clear?


RyanJ

cybercampbell
09-05-2004, 10:09 AM
like this:

<table width="495" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img name="jpg1" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg2" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg3" src="" width="32" height="32" alt=""></div></td>
</tr>
<tr>
<td><div align="center">name1</div></td>
<td><div align="center">name2</div></td>
<td><div align="center">name3</div></td>
</tr>
<tr>
<td><div align="center"><img name="jpg4" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg5" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg6" src="" width="32" height="32" alt=""></div></td>
</tr>
<tr>
<td><div align="center">name4</div></td>
<td><div align="center">name5</div></td>
<td><div align="center">name6</div></td>
</tr>
</table>

what do you think.....easy?

cybercampbell
09-05-2004, 10:21 AM
and I also need to put back in the "Back" & "Next" so that I can reload the page with the new vairiables to get the next or the previouse 6 jpgs.

I looked back at the code from before but how do I make it reload the page or is how you showed before already doing that.

Thanks for all you help.

Chris

sciguyryan
09-05-2004, 10:24 AM
I'll have a go.


RyanJ

sciguyryan
09-05-2004, 10:53 AM
Sorry, I'm not that good with looping structures and so,I can't get it to display the way you want.

And to do the next and back lines would be easy all you have to do is this:

create a link something like this:


echo "<a href='YourPage.php?num2=" . num2 + 6 . "&num1=" . num1 + 6 . "'>Forward</a>";



And the reverse for the back link :)


echo "<a href='YourPage.php?num2=" . num2 - 6 . "&num1=" . num1 - 6 . "'>Forward</a>";


RyanJ

cybercampbell
09-05-2004, 12:55 PM
Hi everyone that's help...Thanks heaps.

I just have one problem:

I can't get the "Back" and "Next" to work. see the bottom of the code:


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 1;
// Loop through the files
echo '<table>';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == "jpg"){
echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "'><br />" . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "</td></tr>";

$num++;
}

}
}
echo '</table>';
echo '<a href="gallery.php?num2=" . num2 - 6 . "&num1=" . num1 - 6 . "">Back</a>';
echo ' | ';
echo '<a href="gallery.php?num2=" . num2 + 6 . "&num1=" . num1 + 6 . "">Next</a>';
// Close
closedir($dir_handle);
?>

I must have stuffed it up.

Any suggestions?

Cheers
Chris

cybercampbell
09-05-2004, 01:25 PM
I aslo did this:


echo "<a href='gallery.php?num2=" . num2 - 6 . "&num1=" . num1 - 6 . "'>Back</a>";
echo " | ";
echo "<a href='gallery.php?num2=" . num2 + 6 . "&num1=" . num1 + 6 . "'>Next</a>";


But it just printed this:

-12'>Back | 12'>Next

Any ideas?

Chris

sciguyryan
09-05-2004, 01:38 PM
Sorry, I made another mistake ;):


echo '<a href="gallery.php?num2=' . (num2 - 6) . '&num1=' . (num1 - 6) . '">Back</a>';
echo ' | ';
echo '<a href="gallery.php?num2=' . (num2 + 6) . '&num1=' . (num1 + 6) . '">Next</a>';



That should work fine.

RyanJ

cybercampbell
09-05-2004, 02:16 PM
Hi mate

I'm realy sorry about this but it doesn't work.

The new Back and Next are now links and seem to send the variables but all I get back is a blank screen and the links...no jpgs.

here is the updated code. I've made a few changes to the tables but that should have caused any problems.


<?php
//Variables
if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 6;
}

//Path
$path = "gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = 1;
// Loop through the files
echo '<table border="0">';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if($file != "." || $file != ".." || $file != "gallery.php" ){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == "jpg"){
echo "<tr><td><div align='center'><img width=\"100\" height=\"100\" src='" . $path . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "'></div><div align='center'>" . $pieces[0] . "</div></td></tr>";

$num++;
}

}
}
echo '</table>';
echo '<a href="gallery.php?num2=' . (num2 - 6) . '&num1=' . (num1 - 6) . '">Back</a>';
echo ' | ';
echo '<a href="gallery.php?num2=' . (num2 + 6) . '&num1=' . (num1 + 6) . '">Next</a>';

// Close
closedir($dir_handle);
?>

Paul Jr
09-05-2004, 02:39 PM
I'm surprised you aren't getting any syntax errors; unless they are constants, you need to prepend the dollar sign ($) to the variables.

echo '<a href="gallery.php?num2=' . ($num2 - 6) . '&num1=' . ($num1 - 6) . '">Back</a>';
echo ' | ';
echo '<a href="gallery.php?num2=' . ($num2 + 6) . '&num1=' . ($num1 + 6) . '">Next</a>';

sciguyryan
09-05-2004, 02:40 PM
Hmm, odd that should work.


I'll check that and see if I can work anything else out


RyanJ

cybercampbell
09-05-2004, 02:50 PM
That helped.

I get the right variables now...

But only the first page shows jpgs.

aaaahhhh!!!!

I've attached the files as they are on my server.

Cheers
Chris

cybercampbell
09-06-2004, 04:26 AM
I've had a play around and it must be something to do with these lines of code.....I Think.

if(isset($_GET["num1"])) {
$num1 = $_GET["num1"];
} else {
$num1 = 1;
}
if(isset($_GET["num2"])) {
$num2 = $_GET["num2"];
} else {
$num2 = 9;
}

$num = 1;
$num >= $num1 && $num < $num2

anything from 1 will work I tried 1 to 6, 1 to 9, 1 to 18.
They all worked by both methods, either setting them in the php code and in the link.

i.e.
gallery.php?num1=1&num2=18

but as soon as I try starting from another group,

i.e.
gallery.php?num1=12&num2=18

I get a blank screen.

I hope this can spark some ideas.

Cheers
Chris

Da Warriah
09-06-2004, 08:58 AM
If you're setting $num as 1, and then running it through this: $num >= $num1 && $num < $num2, of course it's not going to work. You've just set $num1 as 12, and then asked PHP is 1 is greater or equal to 12.

Instead of $num = 1, try $num = $num1 and see if that gives you better results.

sciguyryan
09-06-2004, 10:19 AM
This is the coe I've got and I'm glad to say it works :)

Demo: http://chatzone.viperhosting.net/Temporary/Test5.php

Code:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = "Images/";
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = $num1;
// Loop through the files
echo '<table>';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num <= $num2)){ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$files = array();
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if( $extension == "jpg"){
echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $extension . "'><br />" . $pieces[0] . "." . $pieces[(count($pieces) - 1)] . "</td></tr>";
$num++;
}

}
}
echo '</table>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?&num1=' . (num1 - 6) . '&num2=' . (num2 - 6) . '">Back</a>';
}
else{
echo '<a href="' . $loc . '?num1=6&num2=1">Back</a>';
}
echo ' | ';
echo '<a href="' . $loc . '?num1=' . (num1 + 6) . '&num2=' . (num2 + 6) . '">Next</a>';
// Close
closedir($dir_handle);
?>


Note you'll need to change your folder location back to yours :)

RyanJ

cybercampbell
09-07-2004, 02:34 AM
Thanks sciguyryan for everything so far. It's looking great.

Just one problem now......the numbers change and go up by the amount chosen...but the images are always the same. I need the next 6 images to be the next 6 images in the directory.
the script on your site is the same.

here is the code I have now...I made a few changes like the first 6 don't show the back link.


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = "gallery/";
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = $num1;
// Loop through the files
echo '<table border="0" align="center">';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$files = array();
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if( $extension == "jpg"){
echo "<tr><td>$num</td><td><img src='" . $path . $pieces[0] . "." . $extension . "'><br />" . $pieces[0] . "</td></tr>";
$num++;
}

}
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6) . '&num2=' . ($num2 - 6) . '">Back</a>';
echo ' | ';
}
else{
}
echo '<a href="' . $loc . '?num1=' . ($num1 + 6) . '&num2=' . ($num2 + 6) . '">Next</a>';
echo '</div>';
// Close
closedir($dir_handle);
?>



Cheers Chris

96turnerri
09-07-2004, 05:25 AM
damn look what i miss i pop away for a day and my threads get high jacked, pesky kids xD,

:p take it away boys, your doing well

sciguyryan
09-07-2004, 12:54 PM
I have no idea what is doing that so, I'll fiddle with the coe and see if I can get it working.


RyanJ

cybercampbell
09-08-2004, 03:04 AM
No...please!

Re-join the thread 96turnerri. still a few creases to iron out of this one.

can't seem to get the jpgs to change to the next 6 and so on and so on.

I have a few more ideas aswell. like...this is how I'd like it formated if posible:



<table width="495" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img name="jpg1" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg2" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg3" src="" width="32" height="32" alt=""></div></td>
</tr>
<tr>
<td><div align="center">name1</div></td>
<td><div align="center">name2</div></td>
<td><div align="center">name3</div></td>
</tr>
<tr>
<td><div align="center"><img name="jpg4" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg5" src="" width="32" height="32" alt=""></div></td>
<td><div align="center"><img name="jpg6" src="" width="32" height="32" alt=""></div></td>
</tr>
<tr>
<td><div align="center">name4</div></td>
<td><div align="center">name5</div></td>
<td><div align="center">name6</div></td>
</tr>
</table>


What do you think?

Chris

cybercampbell
09-08-2004, 03:09 AM
I tried a shot in the dark with this but no go...I though I'd post it to see if I was heading on the right area.


echo '<table border="0" align="center">';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$files = array();
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
$image = $pieces;
if( $extension == "jpg"){
echo "<tr>";
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "</tr>";
}

}
}
echo '</table>';


This formats it the way I want but Doesn't give different images across...I not to sure how to do that I thought maybe something like: $image[0] then $image[1] and $image[2] but I tried that and still no go.

The good part was that the $num number where all set out correctly.

Try it and you'll see what I meen

cybercampbell
09-08-2004, 03:53 AM
Here is an example of the last post, It will make more sence if you see what I meen.

http://members.lycos.co.uk/cybercampbell/gallery/gallery.php

Cheers
Chris

cybercampbell
09-09-2004, 09:00 AM
:( :( :( All the friendly faces have gone :( :( :(

WHAT HAPPENED!!! I thought we where a team?

just kidding around.....

where is everyone? is it the Queens birthday?

Chris

MstrBob
09-11-2004, 10:42 AM
Ok, now I'm really confused by all this. You want two rows of three images (all different, being pulled from your directory) with there name underneath and you want next/back buttons to cycle through. So, what are your current issues and what is the exact code you are using? Let's get this cleared up a bit.

sciguyryan
09-11-2004, 10:51 AM
Originally posted by MstrBob
Ok, now I'm really confused by all this. You want two rows of three images (all different, being pulled from your directory) with there name underneath and you want next/back buttons to cycle through. So, what are your current issues and what is the exact code you are using? Let's get this cleared up a bit.


The problem with the current coe is that when you click next it does not go to the next 5 images it instead shows the same images again.


RyanJ

cybercampbell
09-11-2004, 10:52 AM
Nice one MstrBob....I like your attitude!!

here is the script I have now:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = "gallery/";
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
$num = $num1;
// Loop through the files
echo '<table border="0" align="center">';
while ((false !== ($file = readdir($dir_handle))) && ($num >= $num1 && $num < $num2)){ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$files = array();
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
$image = $pieces;
if( $extension == "jpg"){
echo "<tr>";
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $image[0] . "." . $extension . "'></div><div align='center'>" . $image[0] . "</div></td>";
$num++ ;
echo "</tr>";
}

}
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
echo ' | ';
}
else{
}
echo '<a href="' . $loc . '?num1=' . ($num1 + 6) . '&num2=' . ($num2 + 6) . '"><strong>NEXT</strong></a>';
echo '</div>';
// Close
closedir($dir_handle);
?>

here is where you can see the output:

http://members.lycos.co.uk/cybercampbell/gallery/gallery.php

sorry about the pop ups....it's a free host.

This formats it the way I want but Doesn't give different images across...I not to sure how to do that I thought maybe something like: $image[0] then $image[1] and $image[2] but I tried that and still no go.

when you see the output you'll see exatly what I need 3 images across and 2 down (i may need to change this later to 3 down but that should be easy)

the numbers are there at this point as a guide but I don't realy need them so they can go.

the back and next seems to do the job but i'm just not getting the image to disply or loop (i think is the correct term) one after the other.

does this make any sence?

Thanks for taking a look.

Chris

MstrBob
09-11-2004, 11:44 AM
Okay, try this:

<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 0;
}
}
else{
$num1 = 0;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = "gallery/";
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
$num = $num1;
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$files[] = $file;
}
}
while($num >= $num1 && $num < $num2)
{
$file=$files[$num];
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if( $extension == "JPG"){
if($counter==1||$counter==4){echo "<tr>";}
echo "<td>$num<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $file . "'></div><div align='center'>" . $file . "</div></td>";
$num++ ;
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
} }

echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
echo ' | ';
}
else{
}
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 6) . '"><strong>NEXT</strong></a>';
echo '</div>';
// Close
closedir($dir_handle);
?>

cybercampbell
09-11-2004, 11:50 AM
OK..... at first I got a blank screen and then when I refreshed the browser I got this error:

Fatal error: Maximum execution time of 10 seconds exceeded in /data/members/cybercampbell/htdocs/gallery/gallery.php on line 43

any ideas?

Chris

sciguyryan
09-11-2004, 11:52 AM
Just tested it and you get a fata error:


Fatal error: Maximum execution time of 30 seconds exceeded in /home/ryanj/public_html/Tests/Test1.php on line 46


On this line:


while(($num >= $num1) && ($num < $num2))



RyanJ

sciguyryan
09-11-2004, 12:01 PM
Actually on closer inspection its not that line, its the next line:

$file = $files[$num];

Its trying to change the value all the time using the while.

Isuggest changing the while to a for statement.


RyanJ

MstrBob
09-11-2004, 01:17 PM
Sorry, just checked back. This definately works. I hope.

<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//Path
$path = "gallery/";
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if( $extension == "jpg"){
$files[] = $file;}
}
}
for($num=$num1; $num < ($num2+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
echo "<td>".$num."<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $file . "'></div><div align='center'>" . $file . "</div></td>";
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
echo ' | ';
}
else{
}
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
echo '</div>';
// Close
closedir($dir_handle);
?>

cybercampbell
09-11-2004, 01:27 PM
That's it!!!

Thank you sooooo much.

Wooo Hoooo!!!

Chris

cybercampbell
09-11-2004, 04:19 PM
Ok...at a closer look there are a few things to change.

I need to take of the extention from the file name that is shown under the jpg.

and I was hoping that I could set some variables at at the top of the page.

e.g.

$path = "gallery/"; //easy to move up from were it is.
$extensions = "jpg"; //would be nice to have the option to also show gif's or png's instead of or aswell.
$exclude_files = ".","..","index.php","other.html"; // not that important but would be nice.
$no_images = "6"; // sets 6 images per page and sets the amount next and back

what do you think?

I'm just wanting to make it easier for other people to use and customize.

Cheers
Chris

sciguyryan
09-12-2004, 05:58 AM
Try this:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//********* Config ************
$path = "gallery/"; # Image file location.
$useExtension = "jpg"; # Files extension.
$perPage = 6;

//********* End Config *******

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == $useExtension){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($perPage+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>".$num."<div align='center'><img width=\"100\" height=\"100\" src='" . $path . $file . "'></div><div align='center'>" . $file . "</div></td>";
}
else{
if ($Count < 1){
echo "<td><center>There are no more images!</center></td>";
$Count = 1;
}
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
else{}
if ($Count < 1){
echo ' | ';
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
echo '</div>';
// Close
closedir($dir_handle);
?>



Hope that helps,

RyanJ

cybercampbell
09-12-2004, 07:12 AM
mmmm....Blank screen after I hit next.

I'll look at the code and see if I can work it out.

IT'S TIME I TOOK THE PLUNGE!

I'll check back if I stuff it up.

Cheers
Chris

cybercampbell
09-12-2004, 07:20 AM
by the way.....I like this:

else{
if ($Count < 1){
echo "<td><center>There are no more images!</center></td>";
$Count = 1;
}
}

it was my next suggestion.

nicely done.

Chris

sciguyryan
09-12-2004, 07:28 AM
Sorry, my bad this code works:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//********* Config ************
$path = "gallery/"; # Image file location.
$useExtension = "jpg"; # Files extension.
$imageWidth = 100;
$imageHeight = 100;

//********* End Config *******

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if($extension == $useExtension){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>".$num."<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div><div align='center'>" . $file . "</div></td>";
}
else{
if ($Count < 1){
echo "<td><center>There are no more images!</center></td>";
$Count = 1;
}
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
else{}
if ($Count < 1){
echo ' | ';
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
echo '</div>';
// Close
closedir($dir_handle);
?>

cybercampbell
09-12-2004, 07:52 AM
cool...

just afew more ideas. see what you think.....

1. how would I have it set to eccept more than 1 file extention. i.e. .jpg as well as .gif?

2. have the option to turn on or off the extention in the name of the file. i.e. under image 1 shows the name: Ceramic_9 instead of: Ceramic_9.jpg.
a simple variable like $show_ext = on of $show_ext = off would be great.

3. Have the amount of images in the gallery set by a variable i.e $perPage = 6; or $perPage = 9; this would have to then be reflected in the BACK and NEXT links at the bottom.

Image Height & Width was a great idea.
Let me know what is and isn't posible.

Cheers
Chris

sciguyryan
09-12-2004, 07:59 AM
I'll get working on 1&2 right away :)


RyanJ

cybercampbell
09-12-2004, 08:03 AM
Thanks heaps.. I have learnt so much from this.

I hope soon I'll be able to help and contribute to other peoples ideas and problems.

cheers
Chris :)

sciguyryan
09-12-2004, 08:14 AM
Try this:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//********* Config ************
$path = "gallery/"; # Image file location.
$Extension1 = "gif"; # Main file extension.
$Extension2 = "jpg"; # Secondary file extension
$imageWidth = 100; # Image width
$imageHeight = 100; # Image height
$show_Extension = true; # Allow extension in name below image (true or false).

//********* End Config *******

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];
if ($Extension2 == ""){
$Extension2 = $Extension1;
}

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if(($extension == $Extension1) || ($extension == $Extension2)){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>".$num."<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div>";
$name = explode(".", $file);
$ext = "." . $name[(count($name)-1)];
if ($show_Extension){
echo "<div align='center'>" . $name[0] . $ext . "</div>";
}
else{
echo "<div align='center'>" . $name[0] . "</div>";
}
echo "</td>";
}
else{
if ($Count < 1){
echo "<td><center>There are no more images!</center></td>";
$Count = 1;
}
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
else{}
if ($Count < 1){
echo ' | ';
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
echo '</div>';
// Close
closedir($dir_handle);
?>


Well, I learned from asking too :)

RyanJ

cybercampbell
09-12-2004, 08:15 AM
I just had another thought......:eek:

I think it may be best if the script exist in the same directory as the images but still have the option of setting the path for people that want to set it up in a different directory. my reason for this is (thinking back to my early days, not that long ago :p ) that i keeps the script tidy and simple for beginners. upload 1 folder, contains all the images and the gallery script, maybe use php include to include it in your site somwhere and bingo....instant gallery, no fuss no hassle, just a couple of basic vaiables in the gallery.php.

what do you think.... i've noticed in my ignorance that simply removing the path i.e $path = ""; doesn't work but i'm sure this is an easy one for you guys.

Cheers
Chris

sciguyryan
09-12-2004, 08:34 AM
I don't quite get what you mean, what feature do you want?



RyanJ

cybercampbell
09-12-2004, 08:38 AM
based on what you just did...i did the following. It works but let me know if it's OK to do it this way.

I changed this:
if (is_file($path . $file)){
echo "<td>".$num."<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div>";
To this:
if (is_file($path . $file)){
echo "<td>";
if ($show_number){
echo $num;
}
else{
echo "<br>";
}
echo "<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div>";
The variable set like this:
$show_number = false;

cybercampbell
09-12-2004, 08:41 AM
I don't quite get what you mean, what feature do you want?

RyanJ
sorry mate.

can it be set as default that the script is in the same folder as the images and only have the path set if the user wishes to have the images in a different directory.

I hope that make more sence.

Chris

sciguyryan
09-12-2004, 08:48 AM
Yup, see your learning already :)


Heres the full code now:


<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//********* Config ************
$path = "../Scripts/Images/"; # Image file location.
$Extension1 = "gif"; # Main file extension.
$Extension2 = "jpg"; # Secondary file extension
$imageWidth = 100; # Image width
$imageHeight = 100; # Image height
$show_Extension = true; # Allow extension in name below image (true or false).
$show_Number = true; # Allow numbers to display (true or false).

//********* End Config *******

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];
if ($Extension2 == ""){
$Extension2 = $Extension1;
}

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if(($extension == $Extension1) || ($extension == $Extension2)){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>";
if ($show_Number){
echo $num;
}
else{
echo "<br />";
}
echo "<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div>";
echo "</td>";
$name = explode(".", $file);
$ext = "." . $name[(count($name)-1)];
echo "<td>";
if ($show_Extension){
echo "<div align='center'>" . $name[0] . $ext . "</div>";
}
else{
echo "<div align='center'>" . $name[0] . "</div>";
}
echo "</td>";
}
else{
if ($Count < 1){
echo "<td><div align='center'>&nbsp;&nbsp;&nbsp;[There are no more images!]</div></td>";
$Count = 1;
}
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
else{}
if ($Count < 1){
echo ' | ';
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
echo '</div>';
// Close
closedir($dir_handle);
?>


Anything else needed / wanted?


RyanJ

cybercampbell
09-12-2004, 09:08 AM
Thanks heaps.

Anything else needed / wanted?

only this:

Have the amount of images in the gallery set by a variable i.e $perPage = 6; or $perPage = 9; this would have to then be reflected in the BACK and NEXT links at the bottom.

and this:

can it be set as default that the script is in the same folder as the images and only have the path set if the user wishes to have the images in a different directory.


if it's posible.

Cheers
Chris

sciguyryan
09-12-2004, 09:15 AM
Ok, the first one messed up when Itred i but, I think I know why.

The second one, I bet you can do that (Hint use explode() and $_SERVER["PHP_SELF"]



RyanJ :)

cybercampbell
09-12-2004, 09:51 AM
Ok....I'm not there yet.

I tried this
$path = explode("/", $_SERVER["PHP_SELF"]); # Image file location.

but no luck. if you tell me this part, I'm sure I could work out how to have the script check if the variable $path exists and then use the above if it doesn't.

i.e


//********* Config ************
$image_loc = ""; # Image file location. Leave blank if the same as this script.
$Extension1 = "jpg"; # Main file extension.
$Extension2 = ""; # Secondary file extension
$imageWidth = 100; # Image width
$imageHeight = 100; # Image height
$show_Extension = false; # Allow extension in name below image (true or false).
$show_Number = false; # Allow numbers to display (true or false).

//********* End Config *******

if ($image_loc == ""){
$path = explode("/", $_SERVER["PHP_SELF"]);
}
else
{
$path = $image_loc;
}


tell me if this is rubbish.

Cheers
Chris

sciguyryan
09-12-2004, 10:07 AM
Next you need to work out how to make the new location but to do that you'll need a description of how the explode works so, read this:

http://simpleforums.co.uk/index.php?board=10;action=display;threadid=46

And, another hint you'll need to make a new string for the variable BUT, you'll also need to make shure there is no / infront of the string. If you need help just post what you have and I'll see what I can do :)

RyanJ

sciguyryan
09-12-2004, 10:23 AM
Try this (Workes but, you may want to make some changes):



<?php
//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

//********* Config ************
$path = "../Scripts/Images/"; # Image file location.
$Extension1 = "gif"; # Main file extension.
$Extension2 = "jpg"; # Secondary file extension
$imageWidth = 100; # Image width
$imageHeight = 100; # Image height
$show_Extension = true; # Allow extension in name below image (true or false).
$show_Number = true; # Allow numbers to display (true or false).

//********* End Config *******

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];
if ($Extension2 == ""){
$Extension2 = $Extension1;
}
if ($path == ""){
$Loc = explode("/", $_SERVER["PHP_SELF"]);
if (is_dir($Loc[count($Loc)-2] . "/")){
$loc = $Loc[count($Loc)-2] . "/";
}
elseif (is_dir("../" . $Loc[count($Loc)-2] . "/")){
$loc = "../" . $Loc[count($Loc)-2] . "/";
}
}

// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="0" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle))))
{ // Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if(($extension == $Extension1) || ($extension == $Extension2)){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++)
{
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>";
if ($show_Number){
echo $num;
}
else{
echo "<br />";
}
echo "<div align='center'><img width=\"$imageWidth\" height=\"$imageHeight\" src='" . $path . $file . "'></div>";
echo "</td>";
$name = explode(".", $file);
$ext = "." . $name[(count($name)-1)];
echo "<td>";
if ($show_Extension){
echo "<div align='center'>" . $name[0] . $ext . "</div>";
}
else{
echo "<div align='center'>" . $name[0] . "</div>";
}
echo "</td>";
}
else{
if ($Count < 1){
echo "<td><div align='center'>&nbsp;&nbsp;&nbsp;[There are no more images!]</div></td>";
$Count = 1;
}
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
else{}
if ($Count < 1){
echo ' | ';
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
echo '</div>';
// Close
closedir($dir_handle);
?>

cybercampbell
09-12-2004, 10:29 AM
OK I read the stuff and I think I get it...

I did this:


//********* Config ************
$image_loc = ""; # Image file location.
$Extension1 = "jpg"; # Main file extension.
$Extension2 = ""; # Secondary file extension
$imageWidth = 100; # Image width
$imageHeight = 100; # Image height
$show_Extension = false; # Allow extension in name below image (true or false).
$show_Number = false; # Allow numbers to display (true or false).

//********* End Config *******
if ($image_loc == ""){
$path = explode("/", $_SERVER["PHP_SELF"]);
$path = $path[(count($path) - 2)]."/";
}
else
{
$path = $image_loc;
}


but I get the error: Unable to open gallery/

which is wierd because that is where the images are.

please tell me what I'm doing wrong.

Chris

cybercampbell
09-12-2004, 10:33 AM
Just so i'm not being confussing.... this is what i'm hoping to do.

if:
$image_loc = "gallery/";
then the script know to go the the directory gallery/ to find the images.
if:
$image_loc = "";
then I want the script to know that the images are in the same directory as the script itself.

I hope this makes sence.

Cheers Chris

cybercampbell
09-12-2004, 10:36 AM
sorry...I just got your new post.

I'll check that out.

Chris

cybercampbell
09-12-2004, 10:42 AM
I just got: Unable to open

did it work for you?

edit:

hang on.....I think I stuffed somthing up...let me try again.

Chris

cybercampbell
09-12-2004, 10:50 AM
you code worked if there is a path set...

e.g.

$path = "gallery/";
but if the script is in the same directory as the images and the $path is left blank..

e.g.

$path = "";

it doesn't work.

I get the error: Unable to open

Any ideas?

cybercampbell
09-12-2004, 10:54 AM
Hey....so I was on the right track with this:

if ($image_loc == ""){
$path = explode("/", $_SERVER["PHP_SELF"]);
$path = $path[(count($path) - 2)]."/";
}
else
{
$path = $image_loc;
}

Cooool!!

Chris

sciguyryan
09-12-2004, 11:00 AM
Originally posted by cybercampbell
Hey....so I was on the right track with this:

if ($image_loc == ""){
$path = explode("/", $_SERVER["PHP_SELF"]);
$path = $path[(count($path) - 2)]."/";
}
else
{
$path = $image_loc;
}

Cooool!!

Chris


Yup, you were close.

And, I'm working on the Error ATm.

I'll be back in 2 hours :)

RyanJ

cybercampbell
09-12-2004, 12:48 PM
Ok.... I hope i've done the right thing here....

I've made a few changes to the code, hey, gotta have a go!!!

I've taken out the: echo [There are no more images!] stuff and added some code to remove the Next when the images run out.

could be messy so don't freak out....but it does work so hey, that's something.


<?php
//********* Config ************
$path = "gallery/"; # Image file location, leave blank if the same as this script.
$Extension1 = "jpg"; # Main file extension.
$Extension2 = ""; # Secondary file extension .
$show_Name = false; # Allow the name below image to be shown (true or false).
$show_Extension = false; # Allow extension in name below image (true or false).
$show_Number = false; # Allow numbers to display (true or false).
$imageWidth = 100; # Image width.
$imageHeight = 100; # Image height .
$tableborder= "1"; # set the size of the table border around the images.
$cellspacing= "0";
$cellpadding= "0";
$bordercolor="black" ;
//********* End Config *******

//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}
$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];
if ($Extension2 == ""){
$Extension2 = $Extension1;
}
if ($path == ""){
$Loc = explode("/", $_SERVER["PHP_SELF"]);
if (is_dir($Loc[count($Loc)-2] . "/")){
$loc = $Loc[count($Loc)-2] . "/";
}
elseif (is_dir("../" . $Loc[count($Loc)-2] . "/")){
$loc = "../" . $Loc[count($Loc)-2] . "/";
}
}
// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="'.$tableborder.'" cellspacing="'.$cellspacing.'" cellpadding="'.$cellpadding.'" bordercolor="'.$bordercolor.'" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle)))){
// Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if(($extension == $Extension1) || ($extension == $Extension2)){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++){
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>";
if ($show_Number){
echo $num;
}
else{
//echo "<br />";
}
echo '<div align="center"><img width="'.$imageWidth.'" height="'.$imageHeight.'" src="' . $path . $file . '"></div>';
$name = explode(".", $file);
$ext = "." . $name[(count($name)-1)];
if ($show_Name){
$name = $name;
}
else{
$name = "";
}
if ($show_Extension){
echo "<div align='center'>" . $name[0] . $ext . "</div>";
}
else{
echo "<div align='center'>" . $name[0] . "</div>";
}
echo "</td>";
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
if (($num1 - 6) > 0){
if (($num2) < 20){
echo ' | ';
} }
else{
}
if (($num2) < 20){
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';
}
else{
}
echo '</div>';
// Close
closedir($dir_handle);
?>



Ok....the only thing is that I've set the image limit to 20. like this:

if (($num2) < 20){

but I need to have some code that works out the amount of jpgs/gifs in the directory and sets the limit number.

maybe somthing like this:

if (($num2) < $limit){


Feel free to clean it up if it needs it or just get rid of it if it's rubbish.

Chris

sciguyryan
09-12-2004, 01:07 PM
Great, youdidit before I got back :)


Nope, the code works, so there is no need to change anything :)



Anything else needed?


RyanJ

cybercampbell
09-12-2004, 01:43 PM
No... the code doesn't work properly yet.

if the $path is left empty it should know that the images are in the same directory as the script.

e.g.
$path = "";

but I still get the error: Unable to open gallery/

also is there a way of getting the number of images in the directory?

while Looping through the files there must be a way of getting that number.

OK, that's it.

Chris

sciguyryan
09-12-2004, 01:48 PM
Originally posted by cybercampbell
No... the code doesn't work properly yet.

if the $path is left empty it should know that the images are in the same directory as the script.

e.g.
$path = "";

but I still get the error: Unable to open gallery/

also is there a way of getting the number of images in the directory?

while Looping through the files there must be a way of getting that number.

OK, that's it.

Chris


To get how many files all you have to do is do this:

$Var = (count($files) - 1);

And then this:

echo "There are $files in the directory.";

And I can't work on the code ATM ecause my server is down :(

RyanJ

cybercampbell
09-12-2004, 02:04 PM
hey, hey, i did it....thanks.

here is the updated code:


<?php
//********* Config ************
$path = "gallery/"; # Image file location, leave blank if the same as this script.
$Extension1 = "jpg"; # Main file extension.
$Extension2 = ""; # Secondary file extension .
$show_Name = false; # Allow the name below image to be shown (true or false).
$show_Extension = false; # Allow extension in name below image (true or false).
$show_Number = false; # Allow numbers to display (true or false).
$imageWidth = 100; # Image width.
$imageHeight = 100; # Image height .
$tableborder= "1"; # set the size of the table border around the images.
$cellspacing= "0";
$cellpadding= "0";
$bordercolor="black" ;
//********* End Config *******

//Variables
if (isset($_GET["num1"])){
if ($_GET["num1"] > 0){
$num1 = $_GET["num1"];
}
else{
$num1 = 1;
}
}
else{
$num1 = 1;
}
if (isset($_GET["num2"])){
if ($_GET["num1"] > 0){
$num2 = $_GET["num2"];
}
else{
$num2 = 6;
}
}
else{
$num2 = 6;
}

$loc = explode("/", $_SERVER["PHP_SELF"]);
$loc = $loc[(count($loc) - 1)];
if ($Extension2 == ""){
$Extension2 = $Extension1;
}
if ($path == ""){
$Loc = explode("/", $_SERVER["PHP_SELF"]);
if (is_dir($Loc[count($Loc)-2] . "/")){
$loc = $Loc[count($Loc)-2] . "/";
}
elseif (is_dir("../" . $Loc[count($Loc)-2] . "/")){
$loc = "../" . $Loc[count($Loc)-2] . "/";
}
}
// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
echo '<table border="'.$tableborder.'" cellspacing="'.$cellspacing.'" cellpadding="'.$cellpadding.'" bordercolor="'.$bordercolor.'" align="center">';
$counter=1;
while ((false !== ($file = readdir($dir_handle)))){
// Check the numbers from the original GETs.
if ($file != "." || $file != ".." || $file != $loc){
$pieces = explode('.', $file);
$extension = $pieces[(count($pieces) - 1)];
if(($extension == $Extension1) || ($extension == $Extension2)){
if (is_file($path . $file)){
$files[] = $file;
}
}
}
}
for($num=$num1; $num < ($num2+1); $num++){
$file=$files[($num-1)];
if($counter==1||$counter==4){echo "<tr>";}
if (is_file($path . $file)){
echo "<td>";
if ($show_Number){
echo $num;
}
else{
//echo "<br />";
}
echo '<div align="center"><img width="'.$imageWidth.'" height="'.$imageHeight.'" src="' . $path . $file . '"></div>';
$name = explode(".", $file);
$ext = "." . $name[(count($name)-1)];
if ($show_Name){
$name = $name;
}
else{
$name = "";
}
if ($show_Extension){
echo "<div align='center'>" . $name[0] . $ext . "</div>";
}
else{
echo "<div align='center'>" . $name[0] . "</div>";
}
echo "</td>";
}
if($counter==3||$counter==6){echo "</tr>";}
$counter++;
}
echo '</table>';
echo '<div align="center">';
echo '<br>';
if (($num1 - 6) > 0){
echo '<a href="' . $loc . '?num1=' . ($num1 - 6 ) . '&num2=' . ($num2 - 6) . '"><strong>BACK</strong></a>';
}
$limit = (count($files) - 1);
if (($num1 - 6) > 0){
if (($num2) < $limit){
echo ' | ';
}
}
else{
}
if (($num2) < $limit){
echo '<a href="' . $loc . '?num1=' . ($num) . '&num2=' . ($num + 5) . '"><strong>NEXT</strong></a>';

}
else{
}
echo '</div>';
// Close
closedir($dir_handle);
?>



just these two things to go:

1.
if the $path is left empty it should know that the images are in the same directory as the script.

e.g.

$path = "";

but I still get the error: Unable to open gallery/

2.
Have the amount of images in the gallery set by a variable i.e $perPage = 6; or $perPage = 9; this would have to then be reflected in the BACK and NEXT links at the bottom.

Thanks for all your help.

I'll check back tomorrow.

Cheers
Chris

MstrBob
09-12-2004, 06:01 PM
Okay, so now you can have it in the same directory or otherwise. You can specify the maximum number of pictures and how many pictures you want in each row. And now it's all in valid HTML 4.01 Strict! ;)

I'm worried the forum might screw up the code (has a tendancy to do that) so I'm going to include a zip file...

cybercampbell
09-13-2004, 02:19 AM
Wooo Hooo!!!

It's done....well I can't think of anything else.

The only thing I had to change in MstrBob's .zip file was:

$Extension1 = "JPG";
to
$Extension1 = "jpg";

It didn't work for me with the capitals.

apart from that...I love it!

This is all thanks to:

MstrBob
sciguyryan
96turnerri
Da Warriah
Paul Jr

and the constant naggings of me :D

all these guys contributed the the final script.

Thanks heaps to all of you.

Cheers
Chris

cybercampbell
09-13-2004, 02:57 AM
ahhh!!! the fun never stops. :D

I have a few questions...mainly for MstrBob but anyone's free to answer.

1. you took out these parts of the <table> tag:

bordercolor="$bordercolor"
align="center"

are they not valid HTML?

can I have them writen a different way.

2. is this ok to add the the script:

//********* Config ************
$img_border = 2;
$alt_text = "test image"
//********* End Config *******
echo '<div style="text-align:center;"><img width="'.$imageWidth.'" height="'.$imageHeight.'" src="' . $path . $file . '" alt="' . $alt_text . '" border="' . $img_border . '"></div>';

I don't want to mess things up.

3. is it acceptable to include the script (without the HTML you added) into my site like this:

<?php
include "path/to/gallery.php";
?>


That's it really

Thanks again...Chris

96turnerri
09-13-2004, 03:56 AM
ignore me im still asleep </EDIT>

ok

1) yes you are correct they are not valid HTML, try doing it using CSS

eg
style="width: 100%; border: 1px solid #cccccc;"

2) yes that looks fine to add

3) should be ;)

cybercampbell
09-13-2004, 04:53 AM
That didn't really work for me.

here is the code:

$tableborder= 1; # set the size of the table border around the images.
$cellspacing= 0;
$cellpadding= 6;

echo '<table border="'.$tableborder.'" cellspacing="'.$cellspacing.'" cellpadding="'.$cellpadding.'" style="margin:auto;">';

I need to set these two as well:

$table_color="#000000" # or whatever colour you like (is the colour of the tables border which above is set to 1).
$table_align="center" # or left or right (centers the whole table in the middle of the page).


I need to set these in the table echo'd above.

this is what I'm trying to emulate:

<table border="1" align="center" cellpadding="6" cellspacing="0" bordercolor="#000000">


Also...what does "margin:auto" do?

should I be over in the CSS forum for this?

Cheers
Chris

sciguyryan
09-13-2004, 10:37 AM
Why bother seeing as there is already a thread for it.


And as to your other question have a look here:

http://www.w3schools.com/css/css_margin.asp


RyanJ

MstrBob
09-13-2004, 04:42 PM
You're so demanding! What's wrong with you! Give me a break! :mad:

j/k :p :D :D :D don't take me seriously...

The new and improved file. And, of course, in Valid HTML 4.01 Strict.

cybercampbell
09-16-2004, 06:30 AM
Thanks to all you guys.

I love the script and it's so easy for beginners to use.

well done and sorry for all the nagging :D

Love your work!
Chris

cybercampbell
09-19-2004, 05:24 AM
OK....I hope this isn't going to P%*s poeple off!!

I want to incorperate this into the script:


// this script creates a thumbnail image from an image file - can be a .jpg .gif or .png file
// where $thumbsize is the maximum width or height of the resized thumbnail image
// where this script is named resize.php
// call this script with an image tag
// <img src="resize.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
$thumbsize = 200;
$imagesource = $_GET['path'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
if ($imagewidth >= $imageheight) {
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = $imageheight * $factor;
}
if ($imageheight >= $imagewidth) {
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = $imagewidth * $factor;
}
$thumb = @imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);
imagejpeg($thumb);
imagedestroy($image);
imagedestroy($thumb);


so the images show in the gallery are the generated Thumbnails and when clicked it pops up a window with the full image.

OR

should this be done with the upload script I'm using to put the images on the server? so the Thumbnails are created then?

I'm not sure about this stuff.

What do you guys think?

also...is the GDimage stuff fairly standard php stuff?

Cheers
Chris

sciguyryan
09-19-2004, 07:28 AM
Well, This could be incorperated into the script, I'd also have a go but my computer is dead atm :(


RyanJ

MstrBob
09-19-2004, 12:28 PM
Hmm...

Well, yes you can. This, however, would be better done with two separate files. Is that okay? I can combine it to one file, but I really think they should be separate.

Basically, there's another file, say, thumb.php And this thumb.php file creates thumbs of each page and is use as the src of each image. This is how I'd approach it.

cybercampbell
09-19-2004, 02:05 PM
OK thanks.

I think I might have a go at this one.

I'll post it after i'm done so you guys can tell me how I went....If that's OK.

Cheers
Chris

sciguyryan
09-19-2004, 02:11 PM
Well, in that case all you'd have to do is create a link arround the image going to:

PageName.php?path=MyImage.gif


RyanJ

MstrBob
09-19-2004, 03:44 PM
Yes, basically, you're just saving the script you gave into a file, like thumb.php, and then all your img src's are like:

<img src="resize.php?path=path/to/file.jpg">

Actually, I'd change that code to use this:


<?
$thumbsize = 100;//size of thumbs
$path='';
$path=$_GET['path'];
if(substr($path, 0, 7) != "http://" && substr($path, -4)==('.jpg'||'.gif'||'.png') && file_exists($path)){
$imagesource = $path;
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
if ($imagewidth >= $imageheight) {
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = $imageheight * $factor;
}
if ($imageheight >= $imagewidth) {
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = $imagewidth * $factor;
}
$thumb = @imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);
header('Content-type: image/jpeg');
imagejpeg($thumb);
imagedestroy($image);
imagedestroy($thumb);
} else { }
?>

sciguyryan
09-19-2004, 03:58 PM
Well, if your going for compatability I'd say this line should eb generated by the file extension of the file too:

header('Content-type: image/jpeg');


RyanJ

MstrBob
09-19-2004, 04:06 PM
Well, no. The thumbnail script produces a jpeg thumbnail no matter if the original was a jpeg, gif, or png. So, it's pointless. It'll always output a jpg thumbnail, hence the outputted header.

cybercampbell
09-19-2004, 04:37 PM
Aahhh!!! the boys are back in town.

I get the way the script works, I'll do that. The reason initialy for having it all in one was to keep it simple for the person using the script. 1 file....you know. but I think having it seperate is fine if you think it's best.

the thing now is to have it so when the link is clicked it pops up a new window with the full sized image in it.

I'm asuming that requires javascript.

Thanks again for your help and advice.

Chris

MstrBob
09-19-2004, 06:16 PM
Not really, in the gallery script, you have the program write out images like this:

echo '<div style="text-align:center;"><a href="'.$path . $file.'" target="_blank"><img width="'.$imageWidth.'" height="'.$imageHeight.'" src="resize.php?path' . $path . $file . '" alt=""></a></div>';

cybercampbell
09-20-2004, 01:54 AM
OK

I've had a shot at somthing but I need some help....

I'm passing the image Width and Height to the thumb.php. this keeps all Configs in the gallery script.

at the moment the thumb script sets the same Width and Height but I'd like them to be set seperately.

I did this in the gallery script:

echo '<div style="text-align:center;"><a href="'.$path . $file.'" target="_blank"><img width="" height="" src="thumb.php?path=' . $path . $file . '&size=' . $imageWidth . 'x' . $imageHeight . '" alt="' . $alt_text . '" border="' . $img_border . '"></a></div>';


the variable for these are set at the top of the page.

this pases this the the thumb script:

thumb.php?path=gallery/image.jpg&size=500x100


I'm then doing this in the thumb.php script:

$size=$_GET['size'];
$thumbsize = explode("x", $size);

if ($imagewidth >= $imageheight) {
$thumbwidth = $thumbsize[0];
$factor = $thumbsize[0] / $imagewidth;
$thumbheight = $imageheight * $factor;
}
if ($imageheight >= $imagewidth) {
$thumbheight = $thumbsize[1];
$factor = $thumbsize[1] / $imageheight;
$thumbwidth = $imagewidth * $factor;
}
$thumb = @imagecreatetruecolor($thumbwidth,$thumbheight);


But I don't quite understand what the if ($imagewidth >= $imageheight) stuff is doing.

I think I did the explode bit right. would it be better to send it as 2 seperate variables or is the way I did OK?

Any ideas?

Cheers
Chris

sciguyryan
09-20-2004, 10:52 AM
Originally posted by MstrBob
Well, no. The thumbnail script produces a jpeg thumbnail no matter if the original was a jpeg, gif, or png. So, it's pointless. It'll always output a jpg thumbnail, hence the outputted header.


Thas a good point did nto think of that one.


RyanJ

MstrBob
09-20-2004, 02:57 PM
You're there. I've encorporated it now, with the link and a 0 border in the css. The thumb works, and it opens a new windows to view the image. You can specify the thumb width and height. What you had to pass the width and height to thumb.php is right, I just made them an if elseif statement with one more elseif added in case height and width are equal. Is it there?

96turnerri
09-20-2004, 04:45 PM
omg forum annoying me i replied to last post, but it wasnt it what like post 12 or 1000, and i cant delete my own posts ffs

cybercampbell
09-21-2004, 02:35 AM
Thanks MstrBob :D

I just have a quick question...I'm a bit confused... you put a function in the gallery script to do the thumbs but It's not, that I can see, being call from anywhere. do I use the function or the thumb.php script?

I would prefer to call the function to keep things simple for the user.

thanks heaps
Chris

cybercampbell
09-21-2004, 07:33 AM
actualy...I have another question.

when you right click on the thumbnail (which may rarely happen) and hit "save image as" it shows as "thumb.php.jpe" is there an easy way to have it show the imagename.jpg?

Not realy that important but I thought it would be tidier.

Cheers
Chris

sciguyryan
09-21-2004, 12:32 PM
This problem was probably been caused by the fact that the image was dynamically generated by the script, I'll have a look to see if I can do anything to help this but, I'm not shure anything can be done.


RyanJ

MstrBob
09-21-2004, 04:58 PM
No. This is the thing, there is no copy of the image being saved or used. This is a thumbnail generated on the fly. The script is outputting an image, right. But, the file location can't change, because there is no copy of the image saved permanently on the server. It's temporary. There's no fix to that, short of actually creating and saving thumbnail images. But if you want this dynamic, it can't be overcome (to my knowledge, at least). Besides, not many people will be saving thumbs, but rather, full size. And even so, people can rename the file to whatever they choose.

cybercampbell
09-21-2004, 05:05 PM
thanks MstrBob

I get what your saying. :D Yes it takes me a while but I get there in the end. ;)

did you get a chance to read my post before that one? about the function in the gallery script.


actualy...I have another question.

when you right click on the thumbnail (which may rarely happen) and hit "save image as" it shows as "thumb.php.jpe" is there an easy way to have it show the imagename.jpg?

Not realy that important but I thought it would be tidier.

Cheers
Chris


Thanks Chris

MstrBob
09-21-2004, 05:55 PM
thumb.php doesn't have to be modified. It gets what it needs the 3 things it needs throught the URI. Thumbnail size is set in the gallery.php, which is the only file which needs editing. Since the thumbnails are now link to the fullsized images, you don't need to enter the full images' size. In fact, the full images can be of varying sizes.

And you can't change the saveas option. The browser simply uses by default the image filename. But the user can change it. ;)

cybercampbell
09-22-2004, 01:18 AM
Cool. Thanks.

I just just got thrown but this:

function createThumb($imagesource, $height, $width)
{
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
elseif($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
elseif($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) exit;
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
if ($imagewidth >= $imageheight) {
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = $imageheight * $factor;
}
if ($imageheight >= $imagewidth) {
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = $imagewidth * $factor;
}
$thumb = @imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);
imagejpeg($thumb);imagedestroy($image);imagedestroy($thumb);
}

which is in the gallery script that you upoaded.

Do I need this in that script or can I delete it? It seems the thumb.php is doing all this work.

Thanks Chris

MstrBob
09-22-2004, 02:23 PM
Oops, yeah. See what happens when you don't use comments? You leave antiquated bits inside...

New zip, just to keep it together and uniform.

MstrBob
09-22-2004, 02:25 PM
Rather, NOW I included the zip.

sorry...

cybercampbell
09-22-2004, 04:12 PM
Thanks :D

You're a legend.

The script rocks.

Thanks
Chris :)

MstrBob
09-22-2004, 04:48 PM
You may shower me with gifts and praise at any time I deem necessary. :D *head expands*