prepare($query); $sth->bindValue(":username", $_SESSION['username'], PDO::PARAM_STR); $sth->bindValue(":issue", $_SESSION['comfile'], PDO::PARAM_STR); $sth->execute(); if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) { $currentpage = intval($row['currentpage']); } else { $currentpage = 0; } $data["startindex"] = $currentpage; $extracted = false; $files = array(); if ( !is_dir($comicoutputfull) ) { mkdir($comicoutputfull, 0755, true); } else { touch($comicoutputfull); $contents = glob($comicoutputfull . "*"); foreach ( $contents as $i ) { $files[] = basename($i); } if ( count($files) != 0 ) { $extracted = true; } } if ( !$extracted ) { $magic = file_get_contents($comicfull, false, null, 0, 4); if ( substr($magic, 0, 2) === "PK" ) { $comtype = "cbz"; } elseif ( $magic === "Rar!" ) { $comtype = "cbr"; } if ( $comtype == "cbz" ) { $zip = new ZipArchive(); $opened = $zip->open($comicfull); if ( !$opened ) { $data["error"] = true; $data["message"] = "Error opening comic file"; } else { for ( $i=0; $i<$zip->numFiles; $i++ ) { $imgname = basename($zip->getNameIndex($i)); if ( ! isset(pathinfo($imgname)['extension']) ) continue; if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue; $myext = strtolower(pathinfo($imgname)['extension']); if ( ! in_array($myext, VALIDIMAGETYPES) ) continue; $imgname = safeFileName($imgname); $imgcontents = $zip->getFromIndex($i); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); if ( $written ) $files[] = $imgname; } $zip->close(); } } elseif ( $comtype == "cbr" ) { $rar = RarArchive::open($comicfull); if ( $rar === false ) { $data["error"] = true; $data["message"] = "Error opening comic file"; } else { $entries = $rar->getEntries(); foreach ( $entries as $entry ) { $outfile = safeFileName(basename($entry->getName())); if ( ! isset(pathinfo($outfile)['extension']) ) continue; if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue; $myext = strtolower(pathinfo($outfile)['extension']); if ( ! in_array($myext, VALIDIMAGETYPES) ) continue; $entry->extract(false, $comicoutputfull . $outfile); $files[] = basename($outfile); } unset($entry); $rar->close(); } } else { $data["error"] = true; $data["message"] = "Invalid comic file format"; sendResponse(); } } natsort($files); $images = array(); $captions = array(); $last = count($files); $count = 0; foreach ( $files as $file ) { $count++; $images[] = $comicoutputurl . $file; $captions[] = substr(basename($comicoutputurl), 0, -4) . ": {$count} of {$last}"; } $data["images"] = $images; $data["captions"] = $captions; sendResponse(); // vim: set ts=3 sw=3 et: