This was working in 7.X version however upon upgrading to 8.0 the page no longer loads. Have tried displaying errors but it breaks. The script is loading images from a specified folder.
<?
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
// image file types to display
$imagetypes = ['image/jpeg', 'image/gif', 'image/png'];
function getImages($dir)
{
// array to hold return value
$retval = [];
// add trailing slash if missing
$dir .= "/";
// full server path to directory
$fulldir = "/path-to-uploads/uploads/";
$d = @dir($fulldir) or die("getImages: Failed opening directory {$dir} for reading");
while(FALSE !== ($entry = $d->read())) {
// skip hidden files
if($entry{0} == ".") continue;
// check for image files
$f = escapeshellarg("{$fulldir}{$entry}");
$mimetype = trim(shell_exec("file -bi {$f}"));
foreach($GLOBALS['imagetypes'] as $valid_type) {
if(preg_match("@^{$valid_type}@", $mimetype)) {
$retval[] = [
'file' => "/{$dir}{$entry}",
'size' => getimagesize("{$fulldir}{$entry}")
];
break;
}
}
}
$d->close();
return $retval;
}
// fetch image details
$images = getImages("uploads");
// display on page
foreach($images as $img) {
//str_replace('images', '', $img['file']);
echo "<div class=\"photo\">";
echo "<form method='post' action='reviewfiles.php'>";
echo "<input type='hidden' name='file_name' value='".$img['file']."'>";
echo "<img width=\"200px\" height=\"100%\" src=\"{$img['file']}\" {$img['size'][3]} alt=\"\">\n";
echo "<br><input type='submit' name='delete_file' value='Delete File'>";
echo "</form></div>";
}?>