echo "<h1>404 Not found</h1>"; exit; }; $DirectusMedia = new TableGateway('directus_files', $ZendDb); $media = $DirectusMedia->select(function ($select) use($id) { $select->where->equalTo('id', $id); $select->limit(1); }); if (0 == $media->count()) { return $notFound(); } $media = $media->current(); if ($filename != $media['name']) { $correctUrl = $app->urlFor('media_proxy_file', array('id' => $id, 'format' => $format, 'filename' => $media['name'])); return $app->redirect($correctUrl); } $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $ZendDb); $storage = $StorageAdapters->find($media['storage_adapter']); $params = @json_decode($storage['params'], true); $params = empty($params) ? array() : $params; $storage['params'] = $params; $MediaStorage = \Directus\Files\Storage\Storage::getStorage($storage); header('Content-type: ' . $media['type']); echo $MediaStorage->getFileContents($media['name'], $storage['destination']); exit; // Prevent Slim from overriding our headers })->conditions(array('id' => '\\d+'))->name('media_proxy_file'); foreach (glob("client_auth_proxies/*.php") as $filename) { require_once $filename; } $app->run();