/** * @param \Components\Http_Scriptlet_Context $context_ * @param \Components\Uri $uri_ */ public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_) { $params = $uri_->getPathParams(); $base64 = end($params); $info = unserialize(\str\decodeBase64Url($base64)); $path = array_shift($info); $id = array_shift($info); $category = array_shift($info); $scheme = array_shift($info); $store = Media::store($path); $file = $store->findByScheme($scheme, $id, $category); header('Content-Length: ' . $file->getSize()->bytes()); readfile((string) $file); }
/** * @param \Components\Http_Scriptlet_Context $context_ * @param \Components\Uri $uri_ */ public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_) { $uri = $context_->getRequest()->getUri(); $extension = $uri->getFileExtension(); $name = $uri->getFilename(true); $uri_->popPathParam(); $pathTarget = Environment::pathWeb() . $uri_->getPath() . '/' . \str\decodeUrl($name, true) . ".{$extension}"; if (false === is_file($pathTarget)) { $fileTarget = Io::file($pathTarget); $directoryTarget = $fileTarget->getDirectory(); if (false === $directoryTarget->exists()) { $directoryTarget->create(); } $info = @json_decode(\str\decodeBase64Url($name)); if (false === isset($info[0])) { throw new Http_Exception('media/scriptlet/engine', sprintf('Not found [%s].', $uri), Http_Exception::NOT_FOUND); } $pathSource = Environment::pathWeb($info[0]); if (false === is_file($pathSource)) { throw new Http_Exception('media/scriptlet/engine', sprintf('Not found [%s].', $uri), Http_Exception::NOT_FOUND); } if (isset($info[1]) || isset($info[2])) { if (!isset($info[1])) { $info[1] = 0; } if (!isset($info[2])) { $info[2] = 0; } Io::image($pathSource)->scale(Point::of($info[1], $info[2]))->saveAs($fileTarget); } else { Io::file($pathSource)->copy($fileTarget); } } header('Content-Length: ' . Io::fileSize($pathTarget)->bytes()); readfile($pathTarget); }
/** * @see \str\decodeBase64Url() decodeBase64Url */ public static function decodeBase64Url($string_) { return \str\decodeBase64Url($string_); }
/** * @param \Components\Point $dimensions_ * * @return \Components\Io_Image_Engine_Gd */ public static function forBase64($base64_) { $instance = new static(); $instance->m_resource = imagecreatefromstring(str\decodeBase64Url($base64_)); return $instance; }