<?php /** * Redirect User */ // check if any folder is assigned to the current user if ($gateKeeper->isAccessAllowed() && $gateKeeper->getUserInfo('dir') !== null) { $userpatharray = array(); $userpatharray = json_decode(GateKeeper::getUserInfo('dir'), true); // check if user has only one folder if (count($userpatharray) === 1) { $cleandir = substr($setUp->getConfig('starting_dir') . $userpatharray[0], 2); // check if user is trying to access to the root if (!isset($_GET['dir']) || strlen($_GET['dir']) < strlen($cleandir)) { ?> <script type="text/javascript"> window.location.replace("?dir=<?php echo $cleandir; ?> "); </script> <?php } } }
/** * Check if all the parts exist, and * gather all the parts of the file together * * @param string $location - the final location * @param string $temp_dir - the temporary directory holding all the parts of the file * @param string $fileName - the original file name * @param string $chunkSize - each chunk size (in bytes) * @param string $totalSize - original file size (in bytes) * @param string $logloc - relative location for log file * * @return uploaded file */ public function createFileFromChunks($location, $temp_dir, $fileName, $chunkSize, $totalSize, $logloc) { global $chunk; $upload_dir = str_replace('\\', '', $location); $extension = File::getFileExtension($fileName); // count all the parts of this file $total_files = 0; foreach (scandir($temp_dir) as $file) { if (stripos($file, $fileName) !== false) { $total_files++; } } $finalfile = FileManager::safeExtension($fileName, $extension); // check that all the parts are present // the size of the last part is between chunkSize and 2*$chunkSize if ($total_files * $chunkSize >= $totalSize - $chunkSize + 1) { // create the final file if (($openfile = fopen($upload_dir . $finalfile, 'w')) !== false) { for ($i = 1; $i <= $total_files; $i++) { fwrite($openfile, file_get_contents($temp_dir . '/' . $fileName . '.part' . $i)); } fclose($openfile); // rename the temporary directory (to avoid access from other // concurrent chunks uploads) and than delete it if (rename($temp_dir, $temp_dir . '_UNUSED')) { Actions::deleteDir($temp_dir . '_UNUSED'); } else { Actions::deleteDir($temp_dir); } $chunk->setSuccess(" <span><i class=\"fa fa-check-circle\"></i> " . $finalfile . " </span> ", "yep"); $chunk->setUserUp($totalSize); $message = array('user' => GateKeeper::getUserInfo('name'), 'action' => 'ADD', 'type' => 'file', 'item' => $logloc . $finalfile); Logger::log($message, ""); if (SetUp::getConfig("notify_upload")) { Logger::emailNotification($logloc . $finalfile, 'upload'); } } else { setError(" <span><i class=\"fa fa-exclamation-triangle\"></i> cannot create the destination file", "nope"); return false; } } }