/** * File upload handler. Saves file into upload folder and saves origin name to cache. * * @return void */ public function handlePluploadFile() { // $this->getParameter('token') is not working if (!array_key_exists($this->getParameterId('token'), $_GET)) { $this->presenter->sendJson(array('status' => 'error', 'message' => 'Token is missing.')); } $token = $_GET[$this->getParameterId('token')]; if (empty($_FILES)) { $this->presenter->sendJson(array('File is missing.')); } $file = new Nette\Http\FileUpload(end($_FILES)); if (!$file->isOk()) { $this->presenter->sendJson(array('status' => 'error', 'message' => $this->getError($file->getError()))); } $tempName = uniqid('np-') . '.' . pathinfo($file->getName(), PATHINFO_EXTENSION); $file->move($this->form->getUploadDir() . '/' . $tempName); $files = $this->form->cache->load($token, function () { return array(); }); $files[] = $file; $this->form->cache->save($token, $files); $this->presenter->sendJson(array('status' => 'success')); }