Better handle thumbnail creation inside archives when files have no extension

This commit is contained in:
Junior 2024-05-29 13:12:03 -04:00
parent c9f6b01fdc
commit aa9bb4ad1a

View File

@ -54,7 +54,9 @@ function makeThumb($item = "") {
$imgdata = null; $imgdata = null;
for ( $i=0; $i<$zip->numFiles; $i++ ) { for ( $i=0; $i<$zip->numFiles; $i++ ) {
$imgname = basename($zip->getNameIndex($i)); $imgname = basename($zip->getNameIndex($i));
$imgext = strtolower(pathinfo($imgname)['extension']); $parts = pathinfo($imgname);
if ( isset($parts['extension']) ) {
$imgext = strtolower($parts['extension']);
if ( (strcmp($lowest, $imgname) > 0) if ( (strcmp($lowest, $imgname) > 0)
&& ((strcasecmp($imgext, "jpg") == 0) && ((strcasecmp($imgext, "jpg") == 0)
|| (strcasecmp($imgext, "png") == 0) || (strcasecmp($imgext, "png") == 0)
@ -63,6 +65,7 @@ function makeThumb($item = "") {
$imgdata = $zip->getFromIndex($i); $imgdata = $zip->getFromIndex($i);
} }
} }
}
$zip->close(); $zip->close();
if ( is_null($imgdata) ) return false; if ( is_null($imgdata) ) return false;
$didwrite = file_put_contents($outfile, $imgdata); $didwrite = file_put_contents($outfile, $imgdata);
@ -74,7 +77,9 @@ function makeThumb($item = "") {
$lowest = "~"; $lowest = "~";
foreach ( $entries as $entry ) { foreach ( $entries as $entry ) {
$imgname = $entry->getName(); $imgname = $entry->getName();
$imgext = strtolower(pathinfo($imgname)['extension']); $parts = pathinfo($imgname);
if ( isset($parts['extension']) ) {
$imgext = strtolower($parts['extension']);
if ( (strcmp($lowest, $imgname) > 0) if ( (strcmp($lowest, $imgname) > 0)
&& ((strcasecmp($imgext, "jpg") == 0) && ((strcasecmp($imgext, "jpg") == 0)
|| (strcasecmp($imgext, "png") == 0) || (strcasecmp($imgext, "png") == 0)
@ -84,6 +89,7 @@ function makeThumb($item = "") {
if ( !$didwrite ) { return false; } if ( !$didwrite ) { return false; }
} }
} }
}
rar_close($rar_file); rar_close($rar_file);
} else { } else {
return false; return false;