public function testRecursiveMkdir() { $app = new WebApplication(__DIR__ . "/app", "/"); $this->assertTrue(Misc::recursiveMkdir($app->cache_dir . "/test/test")); $this->assertTrue(Misc::recursiveUnlink($app->cache_dir . "/test")); }
/** * Stores a received file. The request must be encoded as formdata. * * The first file in the formdata will be used, every other file is ignored. * * An json response will be generated and send back to the client. * { 'success': TRUE|FALSE, [ 'error': errorstring ] } */ public function uploadAction($parameter) { try { if (!($files = $this->request->files())) { return $this->jsonResult(400, 'Failed to upload file.', 'error_upload_failed'); } foreach ($files as $file) { if ($error = $file->getError()) { return $this->jsonResult(400, "Failed to upload file '%s'.", "error_upload_failed_detail", [$file->getError()]); } } $this->initFromSession(); $this->deleteFile(); $dir = $this->getUploadDir(); if (!Misc::recursiveMkdir($dir, 0700)) { return $this->jsonResult(500, "Failed to create upload directory at '%s'.", "error_createdir_failed", [$dir]); } foreach ($files as $file) { $target = "{$dir}/" . $file->getName(); if (!$file->moveTo($target)) { return $this->jsonResult(500, 'Failed to move file.', 'error_move_failed'); } } $this->file = $target; $this->filename = $file->getName(); $this->filesize = $file->getSize(); $this->saveToSession(); $this->cleanFiles(); return $this->jsonResult(); } catch (Exception $e) { return $this->jsonResult(500, $e->getMessage()); } }