예제 #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;
 }
예제 #5
0
파일: test.php 프로젝트: boxtar/prototype
<?php

require 'includes/src/core/config.inc.php';
// ensure current user is logged in:
include UTILITIES . 'authenticate_user.inc.php';
$page_title = 'Remove A User from A Group';
include HEADER;
include UTILITIES . 'brand_img.inc.php';
// Create new User Object:
$user = new User();
if (isset($_POST['submitted'])) {
    if (Token::check($_POST['token'])) {
        if ($user->exists()) {
            // Create new Uploader Object:
            $uploader = new Upload_Image(['root_dir' => USER_UPLOADS . $user->data()->prof_link . '/img/prof/', 'new_dir' => false, 'thumb_required' => true]);
            // Initiate uploading process:
            if ($uploader->process()) {
                // update users avatar_link
                $file_name = $uploader->get_file_name();
                $user->update(['avatar_link' => $file_name]);
                echo '<center><h5 class="green">File successfully uploaded</h5></center><br/>';
            } else {
                $uploader->errors();
            }
        } else {
            echo '<center><h5 class="red">Error uploading - User not found</h5></center><br/>';
        }
    } else {
        echo '<center><h5 class="red">Invalid Form Submission - Please try again</h5></center><br/>';
    }
}