Guest kilbad Posted April 28, 2007 Share Posted April 28, 2007 Below I have posted my gallery script, and wanted to know if the community would give me some feedback on how to make the actual code more efficient/shorter. I am not a professional coder, so I wanted to take this opportunity to learn some new coding techniques. The script works. I just want to be doing things the best, most efficient way. <?php $page = $_GET['page']; $album = $_GET['album']; $album_identification = file_get_contents("$root/photos/$album/id.txt"); if ($page == "") {$page = 1;} if ($album == "") {$album="general";} if (file_exists("$root/photos/$album/thumbnails/small_thumbnail-0.jpg")) {} else { system("chmod -R 777 $root/photos/$album"); $dir = "$root/photos/$album/"; $num = 0; $type = ".jpg"; foreach ( glob ( $dir . "{*.jpg,*.JPG}", GLOB_BRACE ) AS $file ){ rename ( $file, $dir . sprintf("%04d", $start++) . $type );} system("mkdir $root/photos/$album/thumbnails"); system("chmod -R 777 $root/photos/$album/thumbnails"); } $number_on_each_page = 6; $number_of_files = count(glob("$root/photos/$album/*.jpg")); $number_of_pages = $number_of_files / $number_on_each_page; echo "\t\t\t<div class='photo_container'>\n"; echo "\t\t\t\t~ "; for($i = 1; $i <= $number_of_pages; $i++){ if($i == $page){ echo("<span style='font-weight:800;'>".$i."</span> "); }else{ echo("<a href=\"$i\">$i</a> ");} } if(($number_of_pages / $number_on_each_page) < 1){ if($number_of_files == $number_on_each_page) {} else { if($i == $page){ echo("<span style='font-weight:800;'>".$i."</span> "); }else{ echo("<a href=\"$i\">$i</a> ");} } } if (file_exists("$root/videos/$album")){ echo " | <a href='$URL_root/videos/$album'>video</a> ";} echo "~"; echo "<br />\n"; $number = ($page * $number_on_each_page - ($number_on_each_page)); for($i = 1; $i <= $number_on_each_page; $i++) { photo_thumbnail($album,$page,$number); $number++; } echo "\t\t\t</div>\n"; ?> Functions I include for that page from another file:: <?php function buffer($number){ global $buffer; if ($number < 10) { $buffer="000";} else { if (($number >= 10) and ($number <= 99)) { $buffer="00";} else {$buffer="0";}} } function photo_thumbnail($album,$page,$number){ global $root,$URL_root,$buffer; if (file_exists("$root/photos/$album/thumbnails/small_thumbnail-$number.jpg")) { echo "\t\t\t\t<a href='$URL_root/photos/$album/$page/$number'><img class='thumbnail' src='$URL_root/photos/$album/thumbnails/small_thumbnail-$number.jpg' height='188px' width='250px' alt='' /></a>\n"; } else { buffer($starting_number); if (file_exists("$root/photos/$album/$buffer$number.jpg")) { system("chmod -R 777 $root/photos/$album"); system("convert $root/photos/$album/$buffer$number.jpg -resize 250x -quality 100 $root/photos/$album/thumbnails/small_thumbnail-$number.jpg"); system("chmod -R 555 $root/photos/$album"); echo "\t\t\t\t<a href='$URL_root/photos/$album/$page/$number'><img class='thumbnail' src='$URL_root/photos/$album/thumbnails/small_thumbnail-$number.jpg' height='188px' width='250px' alt='' /></a>\n";}} } ?> Thank you all so much for your help in advance! Brendan Link to comment https://forums.phpfreaks.com/topic/49044-how-to-make-this-script-more-efficientshorter/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.