public function processRequest(MMapRequest $request, MMapResponse $response) { $urlName = $request->getGET('downloadFile'); $urlShare = new UrlShare(); $urlShare->setName($urlName); $urlShareController = UrlShareController::getInstance(); $urlShare = current($urlShareController->searchUrl($urlShare)); if ($urlShare) { $passwordUrl = $urlShare->getPassword(); if ($passwordUrl) { $file = new UrlFile(); $file->setId($urlShare->getFileId()); $urlShareController->readFile($file); $passwordRequest = $request->getPOST('password'); if ($passwordRequest == $passwordUrl) { if ($file) { self::downloadFile($file->getPath(), $request, $response); self::registerDownload($urlShare); } else { self::renderNotFoundFile($response); } } else { if ($file) { $fileName = basename($file->getPath()); $currentFile = FSI::getFile($file->getPath()); $size = $currentFile->getSize(); $unim = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); $c = 0; while ($size >= 1024) { $c++; $size = $size / 1024; } $size = number_format($size, $c ? 2 : 0, ',', '.') . ' ' . $unim[$c]; self::renderWrongPassword($fileName, $size, $urlName, $response, $urlShare->getPassword()); } else { self::renderNotFoundFile($response); } } } else { $file = new UrlFile(); $file->setId($urlShare->getFileId()); $urlShareController->readFile($file); if ($file) { self::downloadFile($file->getPath(), $request, $response); self::registerDownload($urlShare); } else { self::renderNotFoundFile($response); } } } else { self::renderNotFoundFile($response); } }
public function processRequest(MMapRequest $request, MMapResponse $response) { $urlName = $request->getGET('download'); if (is_array($urlName)) { exit; } $urlShare = new UrlShare(); $urlShare->setName($urlName); $urlShareController = UrlShareController::getInstance(); $urlShare = current($urlShareController->searchUrl($urlShare)); if ($urlShare) { if ($urlShare->getExpirationDate() < time()) { self::renderErrorMessage($response, 'Url Expired'); return; } $file = new UrlFile(); $file->setId($urlShare->getFileId()); $urlShareController->readFile($file); if ($file) { $fileName = basename($file->getPath()); $currentFile = FSI::getFile($file->getPath()); $size = $currentFile->getSize(); $unim = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); $c = 0; while ($size >= 1024) { $c++; $size = $size / 1024; } $size = number_format($size, $c ? 2 : 0, ',', '.') . ' ' . $unim[$c]; if ($request->issetGET('wrongPassword')) { $wrongPassword = $request->getGET('wrongPassword'); } else { $wrongPassword = 0; } Kernel::exitSystemMode(); self::renderFoundFile($fileName, $size, $urlName, $response, $urlShare->getPassword(), $wrongPassword); } else { self::renderErrorMessage($response, 'File not available'); } } else { self::renderErrorMessage($response, 'File not available'); } }