/** * (non-PHPdoc) * @see \Simplify\Form\Component::onExecuteServices() */ public function onExecuteServices($serviceAction) { switch ($serviceAction) { case \Simplify\Form::SERVICE_UPLOAD: $data = array(); $file = \Simplify::request()->files($this->getName()); try { $upload = new \Simplify\Upload($file); $upload->uploadPath = $this->path; $upload->upload(); $file = $upload->getUploadedPath(); $image['filename'] = $file; $image['thumbUrl'] = $this->getThumbUrl($file, 128, 128); $image['imageUrl'] = $this->getImageUrl($file); $data['success'] = true; $data['image'] = $image; } catch (\Simplify\UploadException $e) { $data['error'] = $e->getErrors(); } $view = $this->getView(\Simplify\View::JSON); $view->copyAll($data); echo $view->render(); exit; break; } }
/** * * @param string $name the key in the $_FILES array * @return string the uploaded file path */ public function upload($name) { try { $file = \Simplify::request()->files($name); $upload = new \Simplify\Upload($file); $upload->uploadPath = $this->path; $upload->upload(); $this->file = $this->path . $upload->getUploadedPath(); return \Simplify\Form::RESULT_SUCCESS; } catch (\Simplify\UploadException $e) { $this->errors = $e->getErrors(); } return \Simplify\Form::RESULT_ERROR; }
/** * (non-PHPdoc) * @see \Simplify\Form\Element::onPostData() */ public function onPostData(\Simplify\Form\Action $action, &$data, $post) { $name = $this->getName(); $file = $this->getValue($data); if (!empty($file)) { if (!$this->fileExists($file) || $post[$name]['delete']) { $this->onDelete($data); $data[$this->getName()] = ''; } } if (!empty($post[$name]['file']['name']) || $this->required) { try { $upload = new \Simplify\Upload($post[$name]['file']); $upload->uploadPath = $this->path; $upload->hashFilename = true; $upload->upload(); $this->onDelete($data); $data[$this->getName()] = $upload->getUploadedPath(); } catch (\Simplify\UploadException $e) { $this->uploadErrors[] = $e; } catch (\Simplify\ValidationException $e) { $this->uploadErrors[] = $e; } } }