public static function removeUnzipDir($dir) { foreach (scandir($dir) as $file) { if ('.' === $file || '..' === $file) { continue; } if (is_dir("{$dir}/{$file}")) { PrestaEbooksEpub::removeUnzipDir("{$dir}/{$file}"); } else { unlink("{$dir}/{$file}"); } } rmdir($dir); }
if (move_uploaded_file($_FILES['prestaebooks_' . $file_type]['tmp_name'], $full_path)) { // unzip epub if ($mime_type == 'application/epub+zip') { $unzip_dir = dirname(__FILE__) . '/../../ebook_files/unzip/'; $unzip_filename = str_replace('.epub', '.zip', $new_filename); $unzip_path = $unzip_dir . $unzip_filename; copy($full_path, $unzip_path); $unzip_dir = PrestaEbooksEpub::unzipEpub($unzip_filename, $file_type, 'unzip'); if ($unzip_dir !== false) { // read table of contents $ebook_toc = PrestaEbooksEpub::getToc($unzip_dir); } else { die('unzip failed'); } // remove zip directory PrestaEbooksEpub::removeUnzipDir($unzip_dir); } // read mobi metadata if ($mime_type == 'application/octet-stream') { if (PrestaEbooksMobi::isMobiFile($full_path) == false) { die('file is not a valid mobi file'); } } } else { die('impossible to move file to server'); } } else { die('mime_type not allowed : ' . $mime_type); } } // SAVE FILE INFOS IN DATABASE VIA CORE CLASS