getParsedBody(); $cuenta = $factory->find(Cuenta::class)->one($post['cuenta']); $file = $request->getUploadedFiles()['archivo']; $valid_media = [ 'text/csv' => 'csvs', 'application/pdf' => 'pdfs', 'application/vnd.ms-excel' => 'xlss', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlss', 'application/json' => 'jsons' ]; if ($file->getError() === 0 and in_array($file->getClientMediaType(), array_keys($valid_media))) { $filenfo = new \SplFileInfo($file->getClientFilename()); $new_name = implode('.', [implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post['fecha']]), $filenfo->getExtension()]); $to = implode(DIRECTORY_SEPARATOR, [$container->get('folders')->uploads, $valid_media[$file->getClientMediaType()], $new_name]); $file->moveTo($to); $status = file_exists($to); } $output = [ 'input' => [ 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'size' => $file->getSize(), 'error' => $file->getError() ], 'new_name' => $new_name, 'uploaded' => $status ]; return $this->withJson($response, $output); } public function uploads(Request $request, Response $response, Handler $handler): Response { $output = $handler->handle(); return $this->withJson($response, $output); } }