create an array of destination names to allow * for multiple indexing * > create an array to allow setting the img_src for * each dest_name index * > create an array of image sizes to allow for * more than the original "thumb, medium, full" * > have the script run one iteration per dest_name * to create the multiple indexes */ /* *** Variables */ /* * dest_top, dest_sub, dest_name and dest_ext will be * used to form the full path and filename to write * each index file to (destination) * In the routine that produces the html output, * page_count will be tacked onto the $dest_name * to number the index files. * * Example: * $dest_top=$DOCUMENT_ROOT; // uses the webserver root * $dest_sub="files"; // a subdirectory under that, * // owned by the webserver user * $dest_name="index"; // base filename to save as * $dest_ext=".html"; // extension to add to the filename * * Using the above examples, and further taking a * $DOCUMENT_ROOT of /var/www as example, the following * would be the first index written: * /var/www/files/index1.html * */ $dest_top=$DOCUMENT_ROOT; $dest_sub="files"; $dest_ext=".htm"; /* * Each d_name array holds: * 0. the base filename to save to (dest_name) * 1. the image source subdirectory to use for that index * 2. the number of images per page * 3. the number of columns to use in the table display * Create as many dest_name arrays as needed, * numbered sequentially from 0 to whatever. */ $d_name[0]=array("tindex", "128", 60, 3); $d_name[1]=array("index", "preview", 30, 2); $d_name[2]=array("bindex", "512", 10, 1); /* * Subdirectories of images: * these will appear as links under the images in the table * the label for each link follows the directory name * The images shown in the index table will come from the * subdirectory name in each $dest_name array above, so, * at a minimum, you must have as many subdirectories as * you have $dest_name[#] above. */ /* * array("subdirectory_name", "href_link") */ $i_sub[0]=array("128"," [128x96]"); $i_sub[1]=array("preview", " [320x240]"); $i_sub[2]=array("512", " [512x384]"); /* *** VERY IMPORTANT! *** Will these index files be stored in their own subdirectory *** under the full_images directory? For instance, in *** ./html/dest_name.dest_ext */ $subdir="yes"; /* * html variables */ $title="images"; $doctype="\n"; $charset="\n"; /* * table variables * note: the number of columns in the table is specified * in dest_name above and all table variables related * to that are calculated later */ $twidth="90%"; $tborder="7"; $talign="center"; $tframe="box"; $trules="cols"; $cpad="4"; $cspace="2"; $tsummary="A table of images"; $thead1="A Mix of Photos"; $_i=""; for ($_count=0; $_count < sizeof($d_name); $_count++) { $cur=$d_name[$_count]; $_i .= "  [ $cur[1] ]  "; } $thead2=$_i; /* * Adjusts for Lynx's poor handling of tables * (using Lynx, which is text-based, is a little * pointless in this case, but... who knows) */ $TD="\n"; if (strstr($HTTP_USER_AGENT,"Lynx")) { $TD="
  • \n"; } /* *** End Variables */ /* * hopefully, no editing is needed beyond this point */ /* * In the current directory, there should be subdirectories * holding the full-size images. * In each of the full-size image directories, there should * be a subdirectory named for each of the variables above. */ $_handle=opendir('.'); $_count=0; while ($_file = readdir($_handle)){ if ($_file != "." && $_file != ".." && is_dir($_file)) { $i_full[$_count]=$_file; $_count=++$_count; } } closedir($_handle); sort($i_full); /* * send some html to keep the browser happy */ echo $doctype; echo "\n"; echo " \n"; echo " $title\n"; echo " \n"; echo " \n"; /* *** NEED to insert something to tell the user what's about to happen * and give an opportunity to back out or edit. */ /* * now find out how many full-size images there are in * each directory * note: each subdirectory in each full image directory * is expected to contain the same filenames as the full-size */ $_count=0; for ($_cnt=0; $_cnt < sizeof($i_full); $_cnt++) { if (chdir($i_full[$_cnt])) { $_top=$i_full[$_cnt]; $_handle=opendir('.'); while ($_file = readdir($_handle)) { if (strstr($_file, ".jpg")) { $i_name[$_count]=$_top . "/" . $_file; $_count=++$_count; } } closedir($_handle); sort($i_name); chdir('..'); } } /* * present a table of images taken from $img_src, * which is element 1 in the current $d_name array, * with each image a clickable link to the full-size image * in $i_full[#] and with a link to the same filename * in each of the subdirectories in the i_sub array(s) */ $total_images=sizeof($i_name); echo " $total_images images
    \n"; /* * loop through the writing once * for each dest_name */ $loops=sizeof($d_name); for ($loops_n=0; $loops_n < $loops; $loops_n++) { $cur=$d_name[$loops_n]; $dest_name=$cur[0]; $img_src=$cur[1]; $per_page=$cur[2]; $tcols=$cur[3]; $t1_span="$tcols"; $t2_span="$tcols"; $tcwid=floor($twidth / $tcols) . "%"; $total_pages=ceil($total_images / $per_page); echo " $total_pages pages at $per_page per page
    \n"; for ($page_count=1; $page_count <= $total_pages; $page_count++) { if ($page_count > 1) { $prev_p=$page_count - 1; $prev_href=$dest_name . $prev_p . $dest_ext; } else { $prev_href=$dest_name . $total_pages . $dest_ext; } if ($page_count < $total_pages) { $next_p=$page_count + 1; $next_href=$dest_name . $next_p . $dest_ext; } else { $next_href=$dest_name . "1" . $dest_ext; } $destination=$dest_top . "/" . $dest_sub . "/" . $dest_name; $destination .=$page_count . $dest_ext; $write_string=""; /* * assemble the html page */ $write_string .=$doctype; $write_string .="\n"; $write_string .=" \n"; $write_string .=" $charset"; $write_string .=" $title\n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" $thead1 \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; for ($rows=0; $rows < $per_page/$tcols; $rows++) { $write_string .=" \n"; for ($cols=0; $cols < $tcols; $cols++) { $write_string .=" $TD"; $i_test=$cols + ($rows * $tcols) + (($page_count -1) * $per_page); if ($i_test < $total_images) { $cur_image=$i_test; $path_name=dirname($i_name[$cur_image]); $base_name=basename($i_name[$cur_image]); /* * If the generated indexes are to eventually be put * in a subdirectory of their own, * then links have to be re-referenced. */ if ($subdir == "yes") { $_s="../"; } else { $_s=""; } $i_disp=$_s . $path_name . "/" . $img_src . "/" . $base_name; $i_point=$_s . $i_name[$cur_image]; $write_string .=" $i_name[$cur_image]
    \n"; $write_string .=" \n"; $write_string .="
    \n"; $subs=sizeof($i_sub); for ($_count=0; $_count < sizeof($i_sub); $_count++) { $_cur=$i_sub[$_count]; $_i=$_s . $path_name . "/" . $_cur[0] . "/" . $base_name; $_ihref=$_cur[1]; $write_string .=" $_ihref\n"; } } $write_string .=" \n"; } $write_string .=" \n"; } $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .=" \n"; $write_string .="
    \n"; $write_string .=" $thead2 \n"; $write_string .="
    \n"; $write_string .=" [ previous ] \n"; $write_string .=" Page $page_count \n"; $write_string .=" [ next ] \n"; $write_string .="
    \n"; for ($_cnt=1; $_cnt <= $total_pages; $_cnt++) { $_ihref=$dest_name . $_cnt . $dest_ext; if ($_cnt == $page_count) { $write_string .=" - $_cnt - \n"; } else { $write_string .=" [ $_cnt ] \n"; } } $write_string .="
    \n"; $write_string .=" [ previous ] \n"; $write_string .=" Page = $page_count \n"; $write_string .=" [ next ] \n"; $write_string .="
    \n"; $write_string .=" \n"; $write_string .="\n"; /* * at this point, the html page is ready and could be * sent to the browser or written to a file */ // echo $write_string; touch($destination); $fp=fopen($destination, "w"); fwrite($fp, $write_string); echo " $destination written
    \n"; } } echo "
    \n"; echo " \n"; echo "\n"; ?>