Jump to content

Dynamic Gallery


calvin182
 Share

Recommended Posts

Adding:

<?php $imgs = array();// opens image directoryif (is_dir($dir)) {if ($dh = opendir($dir)) {while (($file = readdir($dh)) !== false) {if(!is_dir($file)) {$imgs[] = $file; }}closedir($dh);}}// sorts images in reverse orderif ($sorting=="reverse") {rsort($imgs);}else {sort($imgs);};if ($imgkey = array_search($img, $imgs) !== false) {echo "$img $imgkey";};?>

to my show.php returns a 1 for every image. Isn't 1 supposed to be the key? I'm faily certain every image is key 1. Am I doing something wrong?and I've noticed that when you change the output formating from 16images in 4images per row it says 88images total, but if I were to display 5images with 5images per row(so 1row) then the total images now says 90, any idea why it's doing that?

Link to comment
Share on other sites

returns a 1 for every image. Isn't 1 supposed to be the key?
Looks like the post I referred you to was missing a set of parenthesis...
<?php$tester = array("one","two","three","four");if (($key = array_search('four', $tester)) !== false){  echo "$key";  }?>

I'll have to study on the multiplication issue.Are you changing the modula formula when you change your columns?Another thing you might consider is firing up a session and store the img array in a session variable, then you don't have to open the directory after the first read.-hs

Link to comment
Share on other sites

Sending the "img" and "act" back to show.php you can do this:

if (isset($_GET['act'])){    $key = array_search($img, $_SESSION['imgsArray']);    if ($_GET['act'] == 'prev'){        $key--;        if(isset($_SESSION['imgsArray'][$key])){          $img = $_SESSION['imgsArray'][$key];          }        }    if ($_GET['act'] == 'next'){        $key++;        if(isset($_SESSION['imgsArray'][$key])){          $img = $_SESSION['imgsArray'][$key];          }        }}

Your links:

<a href="<?php echo "$domain/$gallery/show.php?img=$img&act=prev";?>">< Prev</a> . .<a href="<?php echo "$domain/$gallery/show.php?img=$img&act=next";?>">Next ></a>

-hs

Link to comment
Share on other sites

i took out the session stuff bc I dont understand it but I was looking around http://www.php.net and http://www.w3chools.com and I couldn't find anything about file modified so I can add that as a sorting option.Also is there any way to filter out the filetypes from the array so if the user has a non image in the folder the script wont try to make an image for it?

Link to comment
Share on other sites

The php function filemtime() returns the file "last modified" as a Unix timestamp.To cover the file types you could include a regular expression pattern in your config file:

$pattern = "/(\.jpg|\.gif|\.png)$/";

Then add a test when you build the array:

      while (($file = readdir($dh)) !== false) {         if(!is_dir($file)  && preg_match($pattern, $file)) {             $imgs[] = $file; }     }

-hs

Link to comment
Share on other sites

with the filemtime() function... I'm trying to figure out how to use it to sort (both olderst and newest) but I'm not sure how to accomplish this when the existing array can't store this information alongside the images so I think I would have to create a second array, or is there a shorter way around this?also the filetype filter is nice :)edit: could this be done with compact() ?

Edited by calvin182
Link to comment
Share on other sites

Using compact might be a better alternative, I put this together using array_multisort() Post back if it's not working just right.

<?php$dir = '.';$imgs = array();$date = array();$name = array();// users method set at next line$method = 'name';// opens image directoryif (is_dir($dir)) {  if ($dh = opendir($dir)) {    while (($file = readdir($dh)) !== false) {        if(!is_dir($file)) {           $imgs[] = $file;           $date[] = filemtime($file);           $name[] = $file; }    }  closedir($dh);  }}if($method == 'date'){array_multisort($date, SORT_DESC, $name, SORT_DESC, $imgs);  }if($method == 'name'){array_multisort($name, SORT_DESC, $date, SORT_DESC, $imgs); }print_r($imgs);?>

-hs

Edited by hacknsack
Link to comment
Share on other sites

That seems to work fine, although I haven't given it a proper test yet.I'm thinking security now and I've written a small login script but I would like your input as to if you think it'll do the job or if it's secure enough.config.php and save.php show this on the first line:

<?php if (isset($_COOKIE['ogalleryauth'])) {$auth = $_COOKIE['ogalleryauth'];} else {$auth = "0";};?>

config.php show this in the body:

<?php if ($auth != "1") {echo "<form id='validate' name='validate' action='validate.php' method='POST'>username: <input type='text' name='username' id='username'/><br/>password: <input type='password' name='password' id='password'/><br/><input type='submit' name='submit' id='submit' value='Submit'/></form>"; exit(0);};?><form id="oneity-config" name="oneity-config" method="POST" action="save.php">

this is validate.php:

<?php$username = "admin";$password = "changeme";include('init.php');$us = $_POST['username'];$pa = $_POST['password'];$domain1 = ".".$domain;if ($us == $username) {$pass1 = "true";} else {$pass1="false";};if ($pa == $password) {$pass2 = "true";} else {$pass1="false";};if ($pass1 == "true" && $pass2 == "true") {setcookie("ogalleryauth", '1', time()+3600, "/", $domain1, 0); header("Location: config.php"); exit(0);};?><html><head><title>Oneity-Gallery Validation</title></head><body bgcolor="#FFFFFF"><?phpecho "<form id='validate' name='validate' action='validate.php' method='POST'>username: <input type='text' name='username' id='username'/><br/>password: <input type='password' name='password' id='password'/><br/><input type='submit' name='submit' id='submit' value='Submit'/></form>";?></body></html>

I might change the

$username = "admin";$password = "changeme";

part so on first run of config.php the user sets it and then allows the user to change that information from that page later on if needed.

Edited by calvin182
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...