I am having issues with two PHP codes which are not displaying images.
My hosting is on PHP 8.3, and it seems pretty selective for working on some but not all.
And it was working just fine until 24h ago.
First code is this (this is on the main page Gallery):
<?php
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."));
$rgIt = new RegexIterator($it, "/^.+.jpg$/i");
$files = iterator_to_array($rgIt);
usort($files, function($a, $b){
if(filectime($a) == filectime($b))
return 0;
return filectime($a) > filectime($b) ? -1 : 1;
});
$files = array_slice($files, 0 , 6);
foreach($files as $v) {
echo "<a href='". $v ."' target='_blank'><img src='". $v ."' /></a>";
}
?>
When I put this one, the page breaks. On the same page there’s another Recursive code that counts the number of total files inside the gallery folder and that doesn’t break.
Second code is this (this is on a category on main page gallery):
<?php
$dir = "./*/*/*/*/*";
$files = glob($dir. '*.jpg', GLOB_BRACE);
usort($files, function($a, $b){
return (filemtime($a) < filemtime($b));
});
$files = array_slice($files, 0, 6);
foreach($files as $file)
echo "<img src='" . $file. "'>";
?>
Now the absolutely weird thing about this is that the same exact code in a sub-directory where this is placed, works just fine. The problem seems related to how deep it goes into searching and I cannot understand why.
I tried if adding a photo on first level category would show it and it did show. So the problem is for it being in several categories.
The structure is:
MAIN FOLDER (where the code doesn’t work)
– Sub-Category
–Sub-Category
—Sub-Category
—-Sub-Category (with jpg files)
On all sub-category levels it works.