PDA

View Full Version : Resolved PHP Photo Album script v2.11 not displaying most recent image



james438
01-20-2011, 06:59 AM
1) Script Title: PHP Photo Album script v2.11

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

3) Describe problem: I notice that the most recent image file is not being displayed. In this case the image that is not being displayed in the gallery is http://www.animeviews.com/images/x23_26.jpg

The gallery is located at http://www.animeviews.com/images/gallery2.php

here are the other files involved:

http://www.animeviews.com/images/ddphpalbum.js
http://www.animeviews.com/images/ddphpalbum.css
http://www.animeviews.com/images/gallery2.phps
http://www.animeviews.com/images/getalbumpics.phps

jscheuer1
01-20-2011, 11:10 AM
Works in IE actually. But that's because two quirky but technically accurate things cancel each other out. Other browsers get it wrong though and the last image is skipped and would be regardless of which it is.

Use the current getalbumpics.php (available on the demo page):


<?
Header("content-type: application/x-javascript");

function returnimages($dirname=".") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo " [$curimage, \"$file\", \"$filedate\"],\n";
$curimage++;
}
}
echo " [\"placeholder\"]\n";
closedir($handle);
}
return($files);
}

$photovar=$_GET['id'];
if (!eregi("^[a-zA-Z0-9_]+$", $photovar)){
echo "alert(\"Photo Album ID must contain only letters, numbers, or underscore, and cannot start with a number\")";
die();
}
echo "var $photovar={\n";
echo " baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n";
echo " images: [\n";
returnimages();
echo " ],\n";
echo " desc: []\n";
echo "}\n";
?>

Or, for the purist (see http://www.dynamicdrive.com/forums/showthread.php?p=225674#post225674 for explanation):


<?php
Header("content-type: application/x-javascript");
if (phpversion() >= 5.1){
@date_default_timezone_set(date_default_timezone_get());
}

function returnimages($dirname=".") {
$pattern='/\.(jpg|jpeg|png|gif|bmp)$/i';
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo " [$curimage, \"$file\", \"$filedate\"],\n";
$curimage++;
}
}
echo ' ["placeholder"]' . "\n";
closedir($handle);
}
}

$photovar=$_GET['id'];
if (!preg_match('/^[a-z_][a-z0-9_]+$/i', $photovar)){
echo 'alert("Photo Album ID must contain only letters, numbers, or underscore, and cannot start with a number")';
die();
}
echo "var $photovar={\n";
echo " baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n";
echo " images: [\n";
returnimages();
echo " ],\n";
echo " desc: []\n";
echo "}\n";
die();
?>

james438
01-20-2011, 07:53 PM
Yuck, I didn't realize that eregi was being used. If not wanting to use deprecated functions makes me a purist then I am definitely a purist.

Thanks for your help :)