/** * 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; }
/** * Write config to file * * @param string $file * @param array $data */ public function write($file = NULL, $data = NULL) { $file or $file = $this->file; $data or $data = $this->toArray(); Filesystem::makeDir(dirname($file)); file_put_contents($file, PHP_FILE_PREFIX . "return " . var_export($data, TRUE) . ';'); }
/** * Handle elFinder requests */ public function connector_action() { $path = $this->user->dir(); Filesystem::makeDir($path); $opts = array('root' => $path, 'URL' => Url::toUri($path), 'rootAlias' => 'Home', 'dotFiles' => false, 'dirSize' => true, 'fileMode' => 0666, 'dirMode' => 0777, 'mimeDetect' => 'internal', 'uploadAllow' => array('image/jpeg', 'image/png', 'image/gif', 'image/jpg'), 'imgLib' => 'gd', 'tmbDir' => '.thumbs', 'tmbAtOnce' => 5, 'tmbSize' => 48, 'fileURL' => true, 'dateFormat' => 'j M Y H:i'); $fm = new elFinder_Object($opts); $fm->run(); }
/** * Upload file * * @param string $name * @param array $options * @return string|boolean */ public function upload() { if (!isset($_FILES[$this->name])) { return FALSE; } $file = $_FILES[$this->name]; $cogear = getInstance(); event('file.preupload', $file); switch ($file['error']) { case UPLOAD_ERR_CANT_WRITE: $this->errors[] = t('Can\'t upload file. Check write permission for temporary folder.', 'File Errors'); break; case UPLOAD_ERR_INI_SIZE: $this->errors[] = t('File size is bigger that it\'s allowed in <b>php.ini</b> (%s).', 'File Errors', ini_get('upload_max_filesize')); break; case UPLOAD_ERR_NO_FILE: $this->isRequired && ($this->errors[] = t('You didn\'t choose file to upload.', 'File Errors')); break; case UPLOAD_ERR_PARTIAL: $this->errors[] = t('Please, upload file once again.', 'File Errors'); break; case UPLOAD_ERR_NO_TMP_DIR: $this->errors[] = t('Temporary directory is not corrected.', 'File Errors'); break; } if ($file['error'] == UPLOAD_ERR_OK) { if ($this->options->allowed_types) { $types = is_string($this->options->allowed_types) ? new Core_ArrayObject(preg_split('#[^a-z]#', $this->options->allowed_types, -1, PREG_SPLIT_NO_EMPTY)) : $this->options->allowed_types; $ext = pathinfo($file['name'], PATHINFO_EXTENSION); $result = FALSE; foreach ($types as $type) { $type == $ext && ($result = TRUE); } !$result && ($this->errors[] = t('Only following types of files are allowed: <b>%s</b>.', 'File Errors', $types->toString('</b>, <b>'))); } $result = Mime::check($file['name'], $file['type']); if ($result !== TRUE) { $this->errors[] = t('File you are trying to upload has unusual MIME-type. It is like <b>%s</b>, but it was expected to be <b>%s</b>', 'File Errors', $file['type'], $result); } $this->options->maxsize && $this->checkMaxSize($file['size'], $this->options->maxsize); if (!$this->options->path) { $this->errors[] = t('Upload path is not defined.', 'File Erros'); } strpos($this->options->path, ROOT) !== FALSE or $this->options->path = UPLOADS . DS . $this->options->path; Filesystem::makeDir($this->options->path); if (!is_dir($this->options->path)) { $this->errors[] = t('Upload path <b>%s</b> doesn\'t exist.', 'File Errors', $this->options->path); } $file['name'] = $this->prepareFileName($file['name']); $file['path'] = $this->options->path . DS . $file['name']; $this->file = new Core_ArrayObject($file); return !$this->errors ? $this->processUpload() : FALSE; } return NULL; }
/** * Constructor * * @param array $options */ public function __construct($options = array()) { isset($options['path']) or $options['path'] = SITE . DS . 'cache'; parent::__construct($options); Filesystem::makeDir($this->path); }
/** * Save to file * * @param string $file */ public function save($file = NULL) { $this->prepare(); $path = $file ? $file : $this->path; Filesystem::makeDir(dirname($path)); switch ($this->info->type) { case IMAGETYPE_JPEG: imagejpeg($this->source, $path, config('image.jpeg.quality', 75)); break; case IMAGETYPE_GIF: imagegif($this->source, $path); break; case IMAGETYPE_PNG: imagepng($this->source, $path, config('image.png.compression', 9)); break; case IMAGETYPE_ICO: imagegd2($this->source, $path); break; } $this->clear(); }