// Variables and math for files within target directory $num_files = 0; $num_rows = 0; $remainder = 0; $i = 1; //three counters $j = 1; $k = 1; // php.ini parameter register_globals should be OFF. // Use superglobal _POST variable to access form data. $alt_text = $_POST['alt_text']; $current_path = $_POST['current_path']; $current_text = $_POST['current_text']; $final_directory = $_POST['final_directory']; $final_path = $_POST['final_path']; ////////////////////////////////////////////////////////////// // BEGINNING OF SECTION THAT CREATES A TABLE OF THUMBNAILS. // THUMBNAILS ARE IN A DIRECTORY INSIDE OF MAIN PHOTOS // DIRECTORY CALLED "thumbs" ////////////////////////////////////////////////////////////// // Fill an array with all items from a directory. if ($handle = opendir($current_path)) { while (false !== ($file_name = readdir($handle))) { $pic_array[] = $file_name; //echo "$file_name
"; //debug } closedir($handle); } // Take only the jpgs into a sorted array. $n=1; //echo "

"; //debug: foreach ($pic_array as $mypic){ $file_ext = strstr($mypic,'.'); if($file_ext == ".jpg" || $file_ext ==".JPG") { $nice_array[$n] = $mypic; //echo "nice_array $n is $nice_array[$n]
\n"; //debug $n = $n+1; } } // Get number of items in array and the remainder when divided by 3 $num_files = count($nice_array); $num_rows = floor($num_files/3); $remainder = $num_files%3; // This is for debugging only. // echo "\n

"; // echo "Number of files: $num_files\n"; // echo "\n

"; // foreach ($pic_array as $mypic){ // echo "$mypic
"; // } // Create a table of thumbnails 3 columns wide echo "\n\n"; // Two FOR loops take care of the complete rows for ($i=1; $i<=$num_rows; $i++) { echo "\n"; for ($j=1; $j<=3; $j++) { echo "\n"; $k=$k+1; } echo "\n"; } // Use this logic to take care of remainder files if ($remainder !== 0){ if ($remainder == 2) { echo "\n"; for ($j=1; $j<=2; $j++) { echo "\n"; $k=$k+1; } echo "\n"; echo "\n"; } elseif ($remainder == 1) { echo "\n"; echo "\n"; $k=$k+1; for ($j=1; $j<=2; $j++) { echo "\n"; } echo "\n\n"; } else warn("Remainder value doesn't make sense.\n"); } echo "\n
\"$alt_text\"
\"$alt_text\"*
\"$alt_text\"*
\n\n";