function extract_zip_archive($filename, $extract_to) { $zip = new zipArchive(); $res = $zip->open($filename); if ($res == TRUE) { $zip->extractTo($extract_to); $zip->close(); } else { return false; } }
public function mdown() { if (!extension_loaded('zip')) { include VIEW_PATH . 'error.php'; exit; } if (extension_loaded('fastdfs_client')) { include VIEW_PATH . 'error.php'; exit; } set_time_limit(2 * 3600); $fac = Factory::getInstance(); $ids = $_REQUEST['ids']; $info = $fac->getFileMap($ids); if (is_numeric($ids)) { $tmp = $info; unset($info); $info[0] = $tmp; } if ($info) { foreach ($info as $v) { // if ($_SESSION['CLOUD_UID'] != $v['uid']) { $pids = str_replace('/', ',', trim($v['path'], '/')); $ids = ($pids ? $pids . ',' : '') . $v['id']; $shares = $fac->getShareByMap($ids); if ($shares) { $keys = array(); foreach ($shares as $y) { $keys[$y['mapId']] = $y['mapId']; $shares[$y['mapId']] = $y; } $shareInfo = $shares[max($keys)]; } else { continue; } if ($shareInfo) { if (strtotime($shareInfo['overTime']) < time() && $shareInfo['overTime'] != '0000-00-00 00:00:00') { continue; } $fac->incrShareDown($shareInfo['id']); if ($shareInfo['pwd'] && !$_SESSION['share'][self::getClientIp() . ':' . $shareInfo['mapId']]) { continue; } } else { continue; } } // if ($v['isdir']) { $list = $fac->getFileMapByPid($v['uid'], $v['id'], 1); if ($list) { foreach ($list as $y) { $dirs[] = $y['location']; } } } else { $dirs[] = $v['location']; } } } else { include VIEW_PATH . 'error.php'; exit; } $zip = new zipArchive(); $zipName = md5(uniqid() . time()) . '.zip'; $zip->open($zipName, ZIPARCHIVE::OVERWRITE); foreach ($dirs as $v) { $zip->addFile($v, basename($v)); } $zip->close(); header('Content-Type:Application/zip'); if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename="' . rawurlencode($zipName) . '"'); } else { if (preg_match("/Firefox/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename*="utf8\'\'' . $zipName . '"'); } else { header('Content-Disposition: attachment; filename="' . $zipName . '"'); } } header('Content-Length:' . filesize($zipName)); session_write_close(); readfile($zipName); ob_flush(); flush(); unlink($zipName); }
} else { $sql_document_root = "select tvalue from config where NAME='DOWNLOAD_PACK_DIR'"; } $res_document_root = mysqli_query($_SESSION['OCS']["readServer"], $sql_document_root); while ($val_document_root = mysqli_fetch_array($res_document_root)) { $document_root = $val_document_root["tvalue"] . '/download/'; } //echo $document_root; //if no directory in base, take $_SERVER["DOCUMENT_ROOT"] if (!isset($document_root)) { $document_root = VARLIB_DIR . '/download/'; if ($protectedGet['type'] == "server") { $document_root .= "server/"; } } $rep = $document_root . $protectedGet["timestamp"] . "/"; $dir = opendir($rep); $tmpfile = tempnam("/tmp", ".zip"); $zipfile->open($tmpfile, ZipArchive::CREATE); while ($f = readdir($dir)) { if (is_file($rep . $f)) { $zipfile->addFile($rep . $f, $f); } } $zipfile->close(); closedir($dir); readfile($tmpfile); unlink($tmpfile); exit; exit; }
if ($db->validTracking($tracking)) { // download a single model if (isset($_REQUEST['modelId']) && !isset($_REQUEST['models'])) { $modelId = $_REQUEST['modelId']; //check if model id is valid if ($db->validModelId($modelId)) { $fileName = "tuned_{$modelId}.idf"; $dir = "filesFolder"; file_put_contents("{$dir}/{$fileName}", $db->getFile($modelId)); $db->downloadFile("{$dir}/{$fileName}"); unlink("{$dir}/{$fileName}"); } } else { $zipName = $tracking . ".zip"; $zip = new zipArchive(); if ($zip->open($zipName, ZIPARCHIVE::CREATE)) { $validModels = true; if (isset($_REQUEST['models'])) { $modelIds = $_REQUEST['models']; //validate foreach ($modelIds as $modelId) { if (!$db->validModelId($modelId)) { $validModels = false; } } } if (!isset($_REQUEST['models']) || !$validModels) { $modelIds = $db->getModelIds($tracking); } //execute this if there are any models if ((int) count($modelIds) > 0) {