Xdega Posted February 28, 2011 Share Posted February 28, 2011 basically this is like 60% written by me with a few copy/paste. What I am looking to do, is clean up this code a little. Functionally it does what I want it to relatively well, but it does look very very messy and I would like it to be a little more tidy. Any suggestions on how to do this? I am no PHP expert as you can most likely tell by the code itself. <?php require("cfg.php"); //FOLDER PATH $dir_cat= $imgpath; $openDir_cat = opendir($dir_cat); while (false !== ($fileNames_cat = readdir($openDir_cat))) { $check_cat = $dir_cat. "/" . $fileNames_cat; $size_cat = @getimagesize($check_cat); // this check mime of file if($fileNames == "." || $fileNames_cat == ".." || strpos($size_cat[mime], "image") === FALSE) { continue; // exclude everything wha is not image } else { $imagesAll_cat[] = $fileNames_cat; // create an array of images } } $imgnr_cat=0; $imgct_cat=count(glob($dir_cat . "*")); //COUNT THE NUMBER OF FILES IN THE UPLOAD DIR. echo '<center><fieldset class=fieldset>'; echo '<legend> IMGS '; echo ' (' .$imgct_cat. ' IMAGES)</legend><div>'; //GET IMAGES AND DISPLAY THEM while ($imgnr_cat<$imgct_cat){ echo '<a href=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>'; echo '<img width=140 height=100 src=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>'; echo '</a>'; $imgnr_cat++; } echo '</div></fieldset></center>'; ?> Link to comment https://forums.phpfreaks.com/topic/229180-help-cleaning-up-my-code-a-little/ Share on other sites More sharing options...
jcbones Posted March 1, 2011 Share Posted March 1, 2011 I don't see anything wrong with the way it is written. As far as tidying it up, just tab to keep the bracketed statements line up. <?php require("cfg.php"); //FOLDER PATH $dir_cat= $imgpath; $openDir_cat = opendir($dir_cat); while (false !== ($fileNames_cat = readdir($openDir_cat))) { $check_cat = $dir_cat. "/" . $fileNames_cat; $size_cat = @getimagesize($check_cat); // this check mime of file if($fileNames == "." || $fileNames_cat == ".." || strpos($size_cat[mime], "image") === FALSE) { continue; // exclude everything wha is not image } else { $imagesAll_cat[] = $fileNames_cat; // create an array of images } } $imgnr_cat=0; //COUNT THE NUMBER OF FILES IN THE UPLOAD DIR. $imgct_cat=count(glob($dir_cat . "*")); echo '<center><fieldset class=fieldset>' .'<legend> IMGS ' .' (' .$imgct_cat. ' IMAGES)</legend><div>'; //GET IMAGES AND DISPLAY THEM while ($imgnr_cat<$imgct_cat) { echo '<a href=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>' .'<img width=140 height=100 src=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>' .'</a>'; $imgnr_cat++; } echo '</div></fieldset></center>'; ?> Link to comment https://forums.phpfreaks.com/topic/229180-help-cleaning-up-my-code-a-little/#findComment-1181027 Share on other sites More sharing options...
Xdega Posted March 1, 2011 Author Share Posted March 1, 2011 Ah, that definitely looks cleaner. I think the "mess" was in the echo/concatenation use and (as you stated) tabbing . Thanks for that. I do think I suffer a little OCD Link to comment https://forums.phpfreaks.com/topic/229180-help-cleaning-up-my-code-a-little/#findComment-1181031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.