diff --git a/ajax/showcomic.php b/ajax/showcomic.php index e3ff453..4ebe149 100644 --- a/ajax/showcomic.php +++ b/ajax/showcomic.php @@ -8,6 +8,7 @@ $data = array(); $data["error"] = false; $data["message"] = ""; $data["validated"] = $validated; +$data["filename"] = ""; if ( !$validated ) { $data["error"] = true; @@ -19,6 +20,7 @@ if ( !$validated ) { if ( isset($_REQUEST['comic']) ) { $comicfull = realpath(COMICSDIR . base64_decode(urldecode($_REQUEST['comic']))); + $data["filename"] = basename($comicfull); if ( $comicfull === false ) exit(); if ( substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR ) exit(); $comic = substr($comicfull, strlen(COMICSDIR)); @@ -58,7 +60,7 @@ if ( $ext == "cbz" ) { //$myext = substr($imgname, -3); if ( ! isset(pathinfo($imgname)['extension']) ) continue; $myext = strtolower(pathinfo($imgname)['extension']); - if ( ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { $imgname = str_replace("#", "", $imgname); $imgcontents = $zip->getFromIndex($i); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); @@ -66,20 +68,18 @@ if ( $ext == "cbz" ) { } } } elseif ( $ext == "cbr" ) { - $junk = `/usr/local/bin/rar e -ep -o+ "$comicfull" "$comicoutputfull"`; - $fh = opendir($comicoutputfull); - while ( false !== ($file = readdir($fh)) ) { - $myfile = $comicoutputfull . $file; - $mynewfile = $comicoutputfull . str_replace("#", "", $file); - //$myext = strtolower(substr($file, -3)); - if ( ! isset(pathinfo($myfile)['extension']) ) continue; - $myext = strtolower(pathinfo($myfile)['extension']); - if ( ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { - rename($myfile, $mynewfile); - $files[] = basename($mynewfile); + $rar = RarArchive::open($comicfull); + $entries = $rar->getEntries(); + foreach ( $entries as $entry ) { + $outfile = str_replace("#", "", basename($entry->getName())); + $entry->extract(false, $comicoutputfull . $outfile); + if ( ! isset(pathinfo($outfile)['extension']) ) continue; + $myext = strtolower(pathinfo($outfile)['extension']); + if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + $files[] = basename($outfile); } } - closedir($fh); + unset($entry); } else { exit(); }