src/Sasedev/Commons/SharedBundle/Controller/VfsController.php
public function fileAction($file = null)
	{
		if (null == $file) {
			return $this->redirect($this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => '/')));
		}

		$cacheDirectory = $this->getParameter('adapter_cache_dir');
		$local = new LocalAdapter($cacheDirectory, true);
		$localadapter = new LocalAdapter($this->getParameter('adapter_files'));
		$adapter = new CacheAdapter($localadapter, $local, 3600);

		$fsAvatar = new Filesystem($adapter);
		if ($this->endswith($file, '/')) {
			if ($fsAvatar->has($file)) {
				$this->setPageTitle($this->translate('indexof',
					array('%dir%' => $this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)))));

				$this->addTwigVar('pagetitle', $this->translate('indexof_raw',
					array('%dir%' => $this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)))));

				$path = substr($file, 1);
				$fs = $fsAvatar->listKeys($path);

				$listfiles = array();
				foreach ($fs['dirs'] as $key) {
					$fulldir = $key . "/";
					$dirname = $key;
					if (substr($key, 0, strlen($path)) == $path) {
						$dirname = substr($dirname, strlen($path));
					}
					if (!strstr($dirname, "/")) {
						$listfiles[$fulldir] = $dirname;
					}
				}
				foreach ($fs['keys'] as $key) {
					$fullfile = $key;
					$filename = $key;
					if (substr($key, 0, strlen($path)) == $path) {
						$filename = substr($filename, strlen($path));
					}
					if (!strstr($filename, "/")) {
						$listfiles[$fullfile] = $filename;
					}
				}
				$this->addTwigVar('fs', $listfiles);

				return $this->render('SasedevCommonsSharedBundle:Vfs:list_files.html.twig', $this->getTwigVars());
			} else {
				throw new NotFoundHttpException();
			}
		}
		if ($fsAvatar->has($file)) {
			if ($fsAvatar->getAdapter()->isDirectory($file)) {
				$file .= "/";

				return $this->redirect($this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)));
			}
			$reqFile = $fsAvatar->get($file);
			$response = new Response();
			$response->headers->set('Content-Type', 'binary');
			$response->setContent($reqFile->getContent());

			return $response;
		} else {
			throw new NotFoundHttpException();
		}
	}
public function fileAction($file = null)
	{
		if (null == $file) {
			return $this->redirect($this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => '/')));
		}

		$cacheDirectory = $this->getParameter('adapter_cache_dir');
		$local = new LocalAdapter($cacheDirectory, true);
		$localadapter = new LocalAdapter($this->getParameter('adapter_files'));
		$adapter = new CacheAdapter($localadapter, $local, 3600);

		$fsAvatar = new Filesystem($adapter);
		if ($this->endswith($file, '/')) {
			if ($fsAvatar->has($file)) {
				$this->setPageTitle($this->translate('indexof',
					array('%dir%' => $this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)))));

				$this->addTwigVar('pagetitle', $this->translate('indexof_raw',
					array('%dir%' => $this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)))));

				$path = substr($file, 1);
				$fs = $fsAvatar->listKeys($path);

				$listfiles = array();
				foreach ($fs['dirs'] as $key) {
					$fulldir = $key . "/";
					$dirname = $key;
					if (substr($key, 0, strlen($path)) == $path) {
						$dirname = substr($dirname, strlen($path));
					}
					if (!strstr($dirname, "/")) {
						$listfiles[$fulldir] = $dirname;
					}
				}
				foreach ($fs['keys'] as $key) {
					$fullfile = $key;
					$filename = $key;
					if (substr($key, 0, strlen($path)) == $path) {
						$filename = substr($filename, strlen($path));
					}
					if (!strstr($filename, "/")) {
						$listfiles[$fullfile] = $filename;
					}
				}
				$this->addTwigVar('fs', $listfiles);

				return $this->render('SasedevCommonsSharedBundle:Vfs:list_files.html.twig', $this->getTwigVars());
			} else {
				throw new NotFoundHttpException();
			}
		}
		if ($fsAvatar->has($file)) {
			if ($fsAvatar->getAdapter()->isDirectory($file)) {
				$file .= "/";

				return $this->redirect($this->generateUrl('sasedev_commons_shared_vfs_files', array('file' => $file)));
			}
			$reqFile = $fsAvatar->get($file);
			$response = new Response();
			$response->headers->set('Content-Type', 'binary');
			$response->setContent($reqFile->getContent());

			return $response;
		} else {
			throw new NotFoundHttpException();
		}
	}
Get Virtual Files Action

@param string $file

@throws NotFoundHttpException
@return Response

@Route(name="sasedev_commons_shared_vfs_files", path="/Vfs{file}", requirements={"file" = ".*"}, defaults={"file" = null})