";
if ($search != "" ){
$dir = 'categories';
// Open the directory
if ($handle = opendir($dir)) {
// Loop through each subdirectory
while (false !== ($subdir = readdir($handle))) {
if ($subdir != "." && $subdir != ".." && is_dir($dir.'/'.$subdir)) {
// Open the subdirectory
if ($subhandle = opendir($dir.'/'.$subdir)) {
// Loop through each file in the subdirectory
while (false !== ($file = readdir($subhandle))) {
$filename_written = $file;
// Find the occurrence in lower or uppercase
$file_l = strtolower($file);
//if ($subdir == $search){echo 'ok';}
// Check if the filename contains the string
// If there is a category with the searched name all the files within that category will be displayed
if (strpos($file_l, $search) !== false || $subdir == $search) {
// Pagination
if($entry >= $ini and $entry < $end){
if ($file == "." || $file == ".."){continue;}
$file_path = $dir.'/'.$subdir.'/'.$file;
// Get size of the file
$filesize = filesize($file_path);
// Checks if is a binary file or small text content
if($filesize > 500){
$contents = $file_path;
} else {
$contents = file_get_contents($file_path);
}
// For get the last dot in the filename
$lastDotIndex = strrpos($contents, ".");
if ($lastDotIndex) {
$filetype = substr($contents, $lastDotIndex + 1);
$filetype = strtolower($filetype);
// Don't show characters or variables after the file extension
$filetype = substr($filetype, 0, 3);
} else{
$filetype = "none";
}
$display_name = $filename_written;
$name_len = strlen($filename_written);
// Cut string if name is long
if ($name_len > 40){
$display_name = substr($display_name, 0, 40) . "...";
}
$img = "";
// Show case be a picture extension
if($filetype == "png" || $filetype == "jpg" || $filetype == "jpeg" || $filetype == "gif"){
$img = " $display_name Comment | ";
}
// Show a thumbnail case exists
if(file_exists('thumbs/' . $subdir . '/' . $filename_written . '.jpg')){
$img = " $display_name Comment | ";
}
// Toggle table colors
// Show in the end the contents that don't are pictures (for don't break the pictures flow the 'continue' is used)
if ($img == ""){$toggle++; $td_color = $toggle % 2 == 0 ? '#FFF' : '#EEE'; $text_result = $text_result . " $filename_written | $subdir | $filetype | Comment |
";$search_break++; continue;}
// Align and format content in three columns
if($collum == 0){echo "";}
echo $img;
$collum++;
if($collum == 3){echo "
"; $collum = 0;}
$search_break++;
}
$entry++;
// Skip the files of the directory when reached the total results
if($search_break == $end){break;}
}
}
if($search_break == $end){break;}
// Close the subdirectory
closedir($subhandle);
}
}
}
// Close the directory
closedir($handle);
}
if ($search_break == 0){
echo "
Not found.";
}
}
echo "
";
echo "
";
if (!$search && !$start && !$result){
echo "Hello!";
}
echo "
";
if ($entry){
for ($i = $start; $i < $start + 20; $i++) {
echo "
$i ";
}
}
echo "
";
?>