示例#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/>';
    }
}