示例#1
0
文件: Gear.php 项目: romartyn/cogear
 /**
  * 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;
 }
示例#2
0
文件: Image.php 项目: romartyn/cogear
 /**
  * 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;
 }
示例#3
0
文件: Gear.php 项目: romartyn/cogear
 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')));
     }
 }
示例#4
0
文件: Image.php 项目: romartyn/cogear
 /**
  * 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;
 }