/** * Upload image */ public function uploadImage() { $upload_path = Filesystem::makeDir(UPLOADS . DS . 'images' . DS . 'pages' . DS . date('Y/m/d/')); $filter = new Form_Filter_MachineName(); if (!empty($_POST['editor_file_link'])) { $file = $upload_path . DS . $filter->value(basename($_POST['editor_file_link'])); $info = Image::getInfo($file); copy($_POST['editor_file_link'], $file); } else { $image = new Upload_Image('file', array('path' => $upload_path)); if ($image->upload()) { $info = $image->getInfo(); $file = $image->file->path; //Ajax::json(array('succes'=>TRUE,'data'=>HTML::img(Url::toUri($image->file->path),$_POST['editor_file_alt'],array('width'=>$info->width,'height'=>$info->height)))); } //Ajax::json(array('success'=>FALSE,'data'=>implode("\n",$image->errors))); } if (isset($file)) { if ($max = config('pages.image.max', '600x600')) { $size = explode('x', $max); sizeof($size) == 1 && ($size[1] = $size[0]); if ($info->width > $size[0] or $info->height > $size[1]) { $image = new Image($file); $image->resize($max); $image->save(); } } exit(Url::toUri($file)); } exit; }
/** * Set value from request * * @return mixed */ public function result() { $image = new Upload_Image($this->name, $this->getAttributes(), $this->validators->findByValue('Required')); if ($result = $image->upload()) { $this->is_fetched = TRUE; $this->image = $image->getInfo(); $this->value = $result; } else { $this->errors = $image->errors; } return $this->value; }
public function index($action = NULL) { switch ($action) { case 'file': $tpl = new Template('Upload.file'); $tpl->show(); break; case 'image': $image = new Upload_Image('file', array('preset' => 'post', 'path' => UPLOADS . DS . 'posts' . DS . date('Y/m/d'))); if ($result = $image->upload()) { exit(HTML::img($result)); } break; default: append('content', HTML::a(Url::gear('upload') . '/file?iframe', t('Upload'), array('rel' => 'modal', 'class' => 'button'))); } }
/** * Set value from request * * @return mixed */ public function result() { $image = new Upload_Image($this->name, $this->getAttributes(), $this->validators->findByValue('Required')); if ($result = $image->upload()) { $this->is_fetched = TRUE; $this->image = $image->getInfo(); $this->value = $result; } else { $this->errors = $image->errors; } if ($this->form->is_ajaxed) { $result = array('value' => $this->value, 'file' => Url::toUri(UPLOADS . $this->value), 'width' => $this->image->width, 'height' => $this->image->height, 'errors' => $this->errors ? strip_tags(implode("\n", $this->errors)) : ''); Ajax::json($result); } // if there is hidden field with the same name — take value from there if (isset($this->form->request[$this->name])) { $this->value = $this->form->request[$this->name]; } return $this->value; }