/** * @covers ::pruneChunks */ public function testUploader_exception() { try { @Uploader::pruneChunks('not/existing/dir', 30); $this->fail(); } catch (FileOpenException $e) { $this->assertSame('failed to open folder: not/existing/dir', $e->getMessage()); } }
public function actionUpload() { /** * Removing old chunks */ if (1 == mt_rand(1, 100)) { Uploader::pruneChunks($this->temp); } $response = Yii::$app->response; $request = Yii::$app->request; $response->format = Response::FORMAT_RAW; if ($this->module->allowCrossDomain) { $response->headers->add('Access-Control-Allow-Origin', $this->module->allowCORSOrigin); $response->headers->add('Access-Control-Allow-Methods', 'GET,HEAD,POST,OPTIONS,TRACE'); $response->headers->add('Access-Control-Allow-Headers', $this->module->allowCORSHeaders); } if ($request->isOptions) { $response->headers->add('Allow', 'GET,HEAD,POST,OPTIONS,TRACE'); return; } $config = new Config(); $config->setTempDir($this->temp); $file = new File($config); $filename = $this->getFlowParams()['flowFilename']; if (is_callable($this->module->fileNameHandler)) { $filename = call_user_func_array($this->module->fileNameHandler, [$filename]); } if ($request->isGet) { if ($file->checkChunk()) { $response->statusCode = 200; } else { $response->statusCode = 204; return; } } else { if ($file->validateChunk()) { $file->saveChunk(); } else { // error, invalid chunk upload request, retry $response->statusCode = 400; return; } } if ($file->validateFile() && $file->save($this->target . "/{$filename}")) { // File upload was completed } else { // This is not a final chunk, continue to upload } }
public function actionRemoveOutdatedFiles() { Uploader::pruneChunks($this->flowConfig->getTempDir(), $this->expirationTime); }