/** * @param $keys */ public function erase(...$keys) { $handle =& $_SESSION; foreach (Arrays::init($keys) as $key) { if (isset($handle[$key])) { $handle =& $handle[$key]; } else { return; } } unset($handle[Arrays::last($keys)]); }
/** * @param $file * @throws ApplicationException */ private static function write($file) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file[TFiles::MTIME]) . ' GMT'); header('Cache-Control: max-age=0'); header('Content-Type: ' . $file[TFiles::CONTENT_TYPE]); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $file[TFiles::MTIME]) { http_response_code(304); return; } $filename = FSTools::hashToFullPath($file[TFiles::SHA1]); if (!file_exists($filename)) { throw new ApplicationException("Internal server error: file not exists!"); } $filesize = filesize($filename); if (isset($_SERVER["HTTP_RANGE"])) { $range = str_replace("bytes=", "", $_SERVER["HTTP_RANGE"]); $start = Arrays::first(explode("-", $range)); } else { $start = 0; } if (isset($range)) { http_response_code(HttpStatusCodes::HTTP_PARTIAL_CONTENT); header("Content-Range: bytes " . $start . "-" . ($filesize - 1) . "/" . $filesize); header("Content-Length: " . ($filesize - $start)); } else { http_response_code(HttpStatusCodes::HTTP_OK); header("Content-Length: " . $filesize); } header("Accept-Ranges: bytes"); set_time_limit(0); withOpenedFile($filename, "rb", function ($fh) use($start) { if ($start > 0) { fseek($fh, $start, SEEK_SET); } while ($data = fread($fh, self::READ_BUFFER_SIZE)) { echo $data; flush(); } }); }
private static function validateListOfTrackIds($track_ids) { switch (gettype($track_ids)) { case "string": if (is_empty($track_ids)) { throw new ControllerException("Incorrect file id(s) specified"); } break; case "array": if (Arrays::any("is_empty", $track_ids)) { throw new ControllerException("Incorrect file id(s) specified"); } break; default: throw new ApplicationException("Incorrect type of argument"); } }