public function putFile(Application $app, Request $request, $path) { $realPath = Path::getRealPath($path, Config::getRootDir()); if (Path::exists($realPath) && Path::isDir($realPath)) { return $this->createResponse(Response::HTTP_BAD_REQUEST, "Directory '{$path}' already exists"); } if ($request->query->getBoolean('is_dir') || $request->request->getBoolean('is_dir')) { if (Path::exists($realPath)) { return $this->createResponse(Response::HTTP_BAD_REQUEST, "Directory '{$path}' already exists"); } mkdir($realPath); } else { $content = $request->getContent(true); if (!is_resource($content)) { return $this->createResponse(Response::HTTP_BAD_REQUEST, "Request has incorrect body"); } $resourceType = get_resource_type($content); if ($resourceType != 'stream') { return $this->createResponse(Response::HTTP_BAD_REQUEST, "Request has incorrect body"); } $newFile = fopen($realPath, 'w'); try { stream_copy_to_stream($content, $newFile); } finally { fclose($newFile); } } $info = Path::getInfo($realPath); $app['fsrapi.cache']->setTimestampForInfo($info, $info->getLastWriteTime()); $response = new Response(); $response->headers->addCacheControlDirective('no-cache', true); $response->headers->addCacheControlDirective('no-store', true); return $response; }
public function testIsDir() { $this->assertTrue(Path::isDir(__DIR__)); $this->assertFalse(Path::isDir(__FILE__)); }