Jump to content

Need help with gallery script [RESOLVED!]


Mutley

Recommended Posts

I've been trying to modify an existing script, almost alot of it has changed but having a few problems. In which I really need help with.

Here is the code:

[code]<table align="center" cellpadding="5">

<?
$build = false;
if(isset($HTTP_GET_VARS["b"]) || isset($HTTP_GET_VARS["build"]))
  $build = true;

$image = ""; 
if(isset($HTTP_GET_VARS["image"]))
  $image = $HTTP_GET_VARS["image"];

$team = $HTTP_GET_VARS['team'];
$game = $HTTP_GET_VARS['game'];

$thumbnail_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";
$thumbnail_width = 160; $thumbnail_height = 120;

$image_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";
$image_width = 640; $image_height = 480;

$source_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";

//The number of thumbs in a row,
//followed by the number of rows in a page.
$row_size = 3;
$page_size = 5;

$row = $HTTP_GET_VARS["row"];
if($row == "")
  $row = 0;

if(is_dir($thumbnail_folder) == false)
  mkdir($thumbnail_folder, 0755);
 
if(is_dir($image_folder) == false)
  mkdir($image_folder, 0755);
 
if(is_dir($source_folder) == false)
  mkdir($source_folder, 0755);


if($build == true)
  {
  //Get an array of all the jpg files in the current source directory.
  $source_files = glob($source_folder . "/*.JPG");
 
  for($index = 0; $index < count($source_files); $index++)
    {
    $original_jpg = imagecreatefromjpeg($source_files[$index]);
    $original_size = getimagesize($source_files[$index]);
    $original_width = $original_size[0]; $original_height = $original_size[1];
   
    $source_file_name = substr($source_files[$index], strrpos($source_files[$index], "/") + 1);
   
    $thumbnail_jpg = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
    imagecopyresized($thumbnail_jpg, $original_jpg, 0, 0, 0, 0,
                      $thumbnail_width, $thumbnail_height, $original_width, $original_height);
    imagejpeg($thumbnail_jpg, $thumbnail_folder . "/" . $source_file_name);
    imagedestroy($thumbnail_jpg);
   
    $image_jpg = imagecreatetruecolor($image_width, $image_height);
    imagecopyresized($image_jpg, $original_jpg, 0, 0, 0, 0,
                      $image_width, $image_height, $original_width, $original_height);
    imagejpeg($image_jpg, $image_folder . "/" . $source_file_name);
    imagedestroy($image_jpg);
                           
    imagedestroy($original_jpeg);
    }
  }
?>

<?
//Get an array of all the jpg files in the current thumbnail directory.
$thumbnail_files = glob($thumbnail_folder . "/*.JPG");
$first_index = $row * $row_size;
$last_index = $first_index + $page_size * $row_size;
if($last_index > sizeof($thumbnail_files))
  $last_index = sizeof($thumbnail_files);

for($index = $first_index; $index < $last_index; $index++) {
?>

<? if($index == $first_index) { ?>
<tr>
<? } ?>

<? if($index != 0 && $index % $row_size == 0 && $image == "") { ?>
</tr><tr>
<? } ?>

<?
$image_file = substr($thumbnail_files[$index], strrpos($thumbnail_files[$index], "/") + 1);
$image_url = "gallerytest.php?team=" . $team . "&subject=2006&game=" . $game . "&row=" . $row . "&image=" . $image_file;
?>

<? if ($image == "") { ?>
<td>
<a onclick="window.open(this.href, 'popupwindow', 'width=700,height=600,scrollbars,resizable'); return false;" href="<?= $image_url ?>">
<img width="150" height="120" src="<?= $thumbnail_files[$index] ?>" border="3" style="border-color:aa5500;" /></a></td>
<? } ?>

<?
$next_index = $index + 1;
if($next_index >= $last_index)
  $next_index = $first_index;
$next_image_file = substr($thumbnail_files[$next_index],
                          strrpos($thumbnail_files[$next_index], "/") + 1);
?>

<!--^ Get Next Image ^-->

<? if($image == $image_file) { ?>
<td colspan="2">
<a href="gallerytest.php?row=<?= $row ?>&image=<?= $next_image_file ?>">
<img src="<?= $image_folder . "/" . $image_file ?>" border="3" style="border-color:aa5500;" /></a>
<br />
<center><a href="javascript:window.close();">Click here to close this Window</a></center>
</td>
</tr>

<!--^ Image full size pop-up ^-->

<?
$previous_index = $index - 1;
if($previous_index < $first_index)
  $previous_index = $last_index - 1;
$previous_image_file = substr($thumbnail_files[$previous_index],
                              strrpos($thumbnail_files[$previous_index], "/") + 1);
?>

<!--^ Get Previous Image ^-->

<tr>
<td>
<a href="gallerytest.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $row ?>&image=<?= $previous_image_file ?>"><b>Previous Image</b></a>
</td>

<td align="right">
<a href="gallerytest.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $row ?>&image=<?= $next_image_file ?>"><b>Next Image</b></a>
</td>
<? } ?>

<? if($index == count($thumbnail_files) - 1) { ?>
</tr>
<? } ?>

<? } ?>

<? if($image == "") { ?>
<tr>
<td colspan="<?= $row_size ?>">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<?
$previous_row = $row - $page_size;

$last_page_size = ceil(sizeof($thumbnail_files) / $row_size) % $page_size;
if($last_page_size == 0)
  $last_page_size = $page_size;

if($previous_row < 0)
  $previous_row = ceil(sizeof($thumbnail_files) / $row_size) - $last_page_size;
?>
<a href="./teamsgallery3.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $previous_row ?>">Previous Page</a>
</td>

<td align="right">
<?
$next_row = $row + $page_size;
if($next_row >= ceil(sizeof($thumbnail_files) / $row_size))
  $next_row = 0;
?>
<a href="./teamsgallery3.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $next_row ?>">Next Page</a>
</td>
</tr>
</table>
</td>
</tr>
<? } ?>
</table>[/code]


The problems are:
[s]
1) For the Next/Previous page, they don't go to the next page? It is stuck on row=5.[/s]

[s]2) The popup doesn't  work with next/previous image either, like above, the URL is broke.[/s]

[b]3) At the moment you need to do a ?b command on the URL to create all the images into thumbnails before the script shows them, I want to remove this feature, so it just automaticly shows the images in the folder, I don't want thumbnails.[/b]


I really need help with this, I've got this far and can't stop now, thanks.  :(

Link to comment
Share on other sites

I've fixed number 2 but stumped on problem 1 at the moment. I think it's because the file is included that it can't find the next row.

The file is called "galleryfind.php" the "teamsgallery3.php" is where it is included. It works find if I do it from galleryfind.php
Link to comment
Share on other sites

Heres what I have done so far:

[code]<table align="center" cellpadding="5">

<?
$build = false;
if(isset($HTTP_GET_VARS["b"]) || isset($HTTP_GET_VARS["build"]))
  $build = true;

$image = ""; 
if(isset($HTTP_GET_VARS["image"]))
  $image = $HTTP_GET_VARS["image"];

$team = $HTTP_GET_VARS['team'];
$game = $HTTP_GET_VARS['game'];

$thumbnail_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";
$thumbnail_width = 160; $thumbnail_height = 120;

$image_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";
$image_width = 640; $image_height = 480;

$source_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";

//The number of thumbs in a row,
//followed by the number of rows in a page.
$row_size = 3;
$page_size = 5;

$row = $HTTP_GET_VARS["row"];
if($row == "")
  $row = 0;

//if(is_dir($thumbnail_folder) == false)
//  mkdir($thumbnail_folder, 0755);
 
//if(is_dir($image_folder) == false)
//  mkdir($image_folder, 0755);
 
//if(is_dir($source_folder) == false)
//  mkdir($source_folder, 0755);


//if($build == true)
// {
  //Get an array of all the jpg files in the current source directory.
  $source_files = glob($source_folder . "/*.JPG");
 
  //for($index = 0; $index < count($source_files); $index++)
    // {
    //$original_jpg = imagecreatefromjpeg($source_files[$index]);
    //$original_size = getimagesize($source_files[$index]);
    //$original_width = $original_size[0]; $original_height = $original_size[1];
   
    //$source_file_name = substr($source_files[$index], strrpos($source_files[$index], "/") + 1);
   
    //$thumbnail_jpg = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
    //imagecopyresized($thumbnail_jpg, $original_jpg, 0, 0, 0, 0,
      //              $thumbnail_width, $thumbnail_height, $original_width, $original_height);
    //imagejpeg($thumbnail_jpg, $thumbnail_folder . "/" . $source_file_name);
    //imagedestroy($thumbnail_jpg);
   
    //$image_jpg = imagecreatetruecolor($image_width, $image_height);
    //imagecopyresized($image_jpg, $original_jpg, 0, 0, 0, 0,
        //              $image_width, $image_height, $original_width, $original_height);
    //imagejpeg($image_jpg, $image_folder . "/" . $source_file_name);
    //imagedestroy($image_jpg);
                           
    //imagedestroy($original_jpeg);
    //}
// }
?>

<?
//Get an array of all the jpg files in the current thumbnail directory.
$thumbnail_files = glob($thumbnail_folder . "/*.JPG");
$first_index = $row * $row_size;
$last_index = $first_index + $page_size * $row_size;
if($last_index > sizeof($thumbnail_files))
  $last_index = sizeof($thumbnail_files);

for($index = $first_index; $index < $last_index; $index++) {
?>

<? if($index == $first_index) { ?>
<tr>
<? } ?>

<? if($index != 0 && $index % $row_size == 0 && $image == "") { ?>
</tr><tr>
<? } ?>

<?
$image_file = substr($thumbnail_files[$index], strrpos($thumbnail_files[$index], "/") + 1);
$image_url = "galleryfind.php?team=" . $team . "&subject=2006&game=" . $game . "&row=" . $row . "&image=" . $image_file;
?>

<? if ($image == "") { ?>
<td>
<a onclick="window.open(this.href, 'popupwindow', 'width=700,height=600,scrollbars,resizable'); return false;" href="<?= $image_url ?>">
<img width="150" height="120" src="<?= $thumbnail_files[$index] ?>" border="3" style="border-color:aa5500;" /></a></td>
<? } ?>

<?
$next_index = $index + 1;
if($next_index >= $last_index)
  $next_index = $first_index;
$next_image_file = substr($thumbnail_files[$next_index],
                          strrpos($thumbnail_files[$next_index], "/") + 1);
?>

<!--^ Get Next Image ^-->

<? if($image == $image_file) { ?>
<td colspan="2">
<a href="galleryfind.php?row=<?= $row ?>&image=<?= $next_image_file ?>">
<img src="<?= $image_folder . "/" . $image_file ?>" border="3" style="border-color:aa5500;" /></a>
<br />
<center><a href="javascript:window.close();">Click here to close this Window</a></center>
</td>
</tr>

<!--^ Image full size pop-up ^-->

<?
$previous_index = $index - 1;
if($previous_index < $first_index)
  $previous_index = $last_index - 1;
$previous_image_file = substr($thumbnail_files[$previous_index],
                              strrpos($thumbnail_files[$previous_index], "/") + 1);
?>

<!--^ Get Previous Image ^-->

<tr>
<td>
<a href="galleryfind.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $row ?>&image=<?= $previous_image_file ?>"><b>Previous Image</b></a>
</td>

<td align="right">
<a href="galleryfind.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $row ?>&image=<?= $next_image_file ?>"><b>Next Image</b></a>
</td>
<? } ?>

<? if($index == count($thumbnail_files) - 1) { ?>
</tr>
<? } ?>

<? } ?>

<? if($image == "") { ?>
<tr>
<td colspan="<?= $row_size ?>">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<?
$previous_row = $row - $page_size;

$last_page_size = ceil(sizeof($thumbnail_files) / $row_size) % $page_size;
if($last_page_size == 0)
  $last_page_size = $page_size;

if($previous_row < 0)
  $previous_row = ceil(sizeof($thumbnail_files) / $row_size) - $last_page_size;
?>
<a href="./teamsgallery3.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $previous_row ?>">Previous Page</a>
</td>

<td align="right">
<?
$next_row = $row + $page_size;
if($next_row >= ceil(sizeof($thumbnail_files) / $row_size))
  $next_row = 0;
?>
<a href="./teamsgallery3.php?team=<?=$team?>&subject=2006&game=<?=$game?>&row=<?= $next_row ?>">Next Page</a>
</td>
</tr>
</table>
</td>
</tr>
<? } ?>
</table>[/code]

I've been trying to solve problem 3, ignoring problem 1 for now, as it is least important. I have tried commenting out some lines in hope that it will display the images without having to create thumbnails (all I want it to do is show the images in a folder, currently, when you upload the images you need to do galleryfind.php?b to create them and only then will they be displayed!)

It hasn't worked what I have commented out, which makes me belive that it is in this code maybe:
[code]$thumbnail_files = glob($thumbnail_folder . "/*.JPG");
$first_index = $row * $row_size;
$last_index = $first_index + $page_size * $row_size;
if($last_index > sizeof($thumbnail_files))
  $last_index = sizeof($thumbnail_files);

for($index = $first_index; $index < $last_index; $index++) {
?>

<? if($index == $first_index) { ?>
<tr>
<? } ?>

<? if($index != 0 && $index % $row_size == 0 && $image == "") { ?>
</tr><tr>
<? } ?>
[/code]

But I can't be sure. As it is rather too complex for me.  :(
Link to comment
Share on other sites

Problem 1 fixed, I'm getting there, that just leaves problem 3 left which I just can't figure out myself.

I just found at the top of the file this (can't belive I missed it):
[code]
build = false;
if(isset($HTTP_GET_VARS["b"]) || isset($HTTP_GET_VARS["build"]))
$build = true;
[/code]

...which is how it creates the thumbnails and displays the images, if ?b then it creates thumbnails and makes images work. If not it displays gallery and if the images in the source foldr havn't been made it doesn't show anything.
Link to comment
Share on other sites

[quote author=Mutley link=topic=108546.msg437085#msg437085 date=1158655398]
Got it but need help with this line:

[code]$thumbnail_files = glob($thumbnail_folder . "/*.jpg");[/code]

If the images are .JPG they don't show but do with .jpg, how do I make it show either show, not case sensitive?
[/quote]

Fixed them all now, lol, so no need to reply, a nice little blog of my problems, I guess I was on at a quiet time. :D

This:
[code]$thumbnail_files = glob($thumbnail_folder . "/*.jpg");[/code]

Should of been:
[code]$thumbnail_files = glob($thumbnail_folder . "/*");[/code]

Thanks.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.