Jump to content

Help cleaning up my code a little?


Xdega

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.