The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ou8125150 (1) [Avatar] Offline
My gallery works (classic) but I have a strange error

Notice: Undefined offset: -1 in

it says it is in line 39 of

here is my

<?php <br /> /* <br /> scan through a directory, listing out all the subfolders and image files <br /> */
function list_dir($dir,$path){
while (false != ($entry = $d->read())){
if (is_dir(implode('/',array($dir,$entry)))){
if (($entry!='.') && ($entry!='..')){
}else if (is_image_file($entry,$path)){
'dirs' => $dirs,
'imgs' => $imgs,
'others' => $others
return $results;

decide whether a file is an image, based on it's name
function is_image_file($entry,$path){
if ($bits[$last]=='jpg'){
//ignore the thumbnails we've already made!
$is_image=($bits[$last-1]!='thumb' && $bits[$last-2]!='thumb');
if ($is_image){
return $is_image;

make sure the image has a thumbnail
function ensure_thumbnail($base_name,$path){
global $basedir,$thumb_max;
if (!file_exists($thumb_name)){
$thumb_x=($source_x > $source_y) ?
$thumb_max :
$thumb_y=($source_x < $source_y) ?
$thumb_max :

build up breadcrumb trail
function get_breadcrumbs($path){
'name' => 'home',
'path' => $tmp_path
foreach ($bits as $i => $value){
if (strlen($value) > 0){
'name' => $value,
'path' => $tmp_path
return $crumbs;

work out whether we're giving close-up of image, or view of thumbnails
function is_close_up($name){
if ($last=='jpg'){ $result=true; }
return $result;

if (isset($_GET['path'])){
if ($cc > 0){
if ($closeup==false){

I looked on line and it said to suppress errors in my php.ini file. This is not an acceptable solution.

Any help is much appreciated.

Message was edited by:
davecrane (149) [Avatar] Offline
Re: Quick Gallery

Looks like this line is the culprit:

$is_image=($bits[$last-1]!='thumb' && $bits[$last-2]!='thumb');

$bits is the image filename split on the '.' delimiter, so we're checking that the image isn't already a thumbnail by looking for the ".thumb.jpg" ending. If $last-1 or $last-2 evaluates to less than zero, you'd get the notice that you're seeing, so to tighten up the code just add a bit of bounds checking.

PHP5 has a pretty flexible error reporting mechanism compared to PHP4, and those Notice messages can be spat out in some volume, in my experience. I usually like to turn them off when I'm playing around with PHP in order to get an Ajax app running smoothly. I don't see why turning off notices on a test server running the exaples from the book is unacceptable, but I'm open to explanations. If you don't want to turn them off, that's fine, just add in some bounds checking to make them go away.

If this was a book about PHP programming (or if I was writing something for production!) I'd take a bit more care over the back-end code, but this code is just a bit of back-end support for the JavaScript. If it really is preventing you from running QuickGallery, then get back to me, and I'll look into it some more.