Exemplo n.º 1
0
 public function handleMenuUpload()
 {
     $filename = $this->user->getMenuFile();
     if (!empty($_FILES['input_menu']['tmp_name']) && is_uploaded_file($_FILES['input_menu']['tmp_name'])) {
         $validImageTypes = array("jpg", "jpeg", "png", "pdf");
         if (filesize($_FILES['input_menu']['tmp_name']) > MAX_IMAGE_UPLOAD_FILESIZE) {
             echo "Upload is too big.";
             return false;
         }
         $menuUpload = new upload($_FILES['input_menu']);
         $menuUploadFolder = ASSETS_PATH . "downloads/";
         $menuFileInfo = pathinfo($_FILES['input_menu']['name']);
         $newFilenameBase = $this->user->getStub() . "_menu";
         $ext = strtolower(pathinfo($_FILES['input_menu']['name'], PATHINFO_EXTENSION));
         if (!in_array($ext, $validImageTypes)) {
             echo "invalidImageType";
             return false;
         }
         if ($menuUpload->uploaded) {
             ## Move uploaded file and resize
             $menuUpload->file_new_name_body = $newFilenameBase;
             $menuUpload->file_overwrite = true;
             $menuUpload->process($menuUploadFolder);
             if ($menuUpload->processed) {
                 $filename = $newFilenameBase . "." . $ext;
             } else {
                 echo $menuUpload->error;
             }
         } else {
             echo $menuUpload->error;
         }
     }
     return $filename;
 }
Exemplo n.º 2
0
 public function beforeSave($options = array())
 {
     if (is_numeric(key($this->data['Foto']))) {
         $produto_id = $this->data['Foto']['produto_id'];
         foreach ($this->data['Foto'] as $key => $foto) {
             if (is_numeric($key)) {
                 if (!empty($foto['tmp_name'])) {
                     App::uses('upload', 'Vendor');
                     $imagem = new upload($foto);
                     if ($imagem->uploaded) {
                         $imagem->resize = true;
                         $imagem->imagem_x = 100;
                         $imagem->imagem_ratio_y = true;
                         $imagem->process('img/produtos/');
                         if ($imagem->processed) {
                             $_foto = array('produto_id' => $produto_id, 'arquivo' => $imagem->file_dst_name);
                             $this->create();
                             $this->save($_foto);
                         } else {
                             throw new Exception($imagem->error);
                         }
                     } else {
                         throw new Exception($imagem->error);
                     }
                 }
             }
         }
         if (!isset($_foto)) {
             return false;
         }
         $this->data['Foto'] = $_foto;
     }
 }
Exemplo n.º 3
0
 public function nuevo()
 {
     //verifica el rol y los permisos de usuario.
     $this->_acl->acceso('nuevo_post');
     //asigna titulo a la vista
     $this->_view->assign('titulo', 'Nuevo Post');
     //coloca el archivos js y js.validate.
     $this->_view->setJsPlugin(array('jquery.validate'));
     $this->_view->setJs(array('nuevo'));
     //si el archivo fue mandado entonces se asignan los valores de $_POST  a la variable datos.
     if ($this->getInt('guardar') == 1) {
         $this->_view->assign('datos', $_POST);
         //verifica si el post tiene titulo
         if (!$this->getTexto('titulo')) {
             $this->_view->assign('_error', 'Debe introducir el titulo del post');
             $this->_view->renderizar('nuevo', 'post');
             exit;
         }
         //verifica si el post tiene cuerpo
         if (!$this->getTexto('cuerpo')) {
             $this->_view->assign('_error', 'Debe introducir el cuerpo del post');
             $this->_view->renderizar('nuevo', 'post');
             exit;
         }
         $imagen = '';
         //verifica si se ha seleccionado un archivo tipo imagen
         if ($_FILES['imagen']['name']) {
             //se define la ruta de la imagen
             $ruta = ROOT . 'public' . DS . 'img' . DS . 'post' . DS;
             //Se crea un objeto upload con idioma español.
             $upload = new upload($_FILES['imagen'], 'es_Es');
             //se especifica el tipo de archivo.
             $upload->allowed = array('image/*');
             //se define un nombre para el archivo.
             $upload->file_new_name_body = 'upl_' . uniqid();
             //Se inicia la carga con la ruta destino especificada
             $upload->process($ruta);
             //si se ha logrado la carga entonces crear una miniatura con upload libreria.
             if ($upload->processed) {
                 $imagen = $upload->file_dst_name;
                 $thumb = new upload($upload->file_dst_pathname);
                 $thumb->image_resize = true;
                 $thumb->image_x = 100;
                 $thumb->image_y = 70;
                 $thumb->file_name_body_pre = 'thumb_';
                 $thumb->process($ruta . 'thumb' . DS);
             } else {
                 $this->_view->assign('_error', $upload->error);
                 $this->_view->renderizar('nuevo', 'post');
                 exit;
             }
         }
         //Luego de guardarse la imagen entonces se guarda el post
         $this->_post->insertarPost($this->getPostParam('titulo'), $this->getPostParam('cuerpo'), $imagen);
         //Se redicciona al index de post.
         $this->redireccionar('post');
     }
     //Se renderiza nuevamente la vista nuevo del post.
     $this->_view->renderizar('nuevo', 'post');
 }
 /**
  * Uploads a new file for the given FileField instance.
  *
  * @param string $name EAV attribute name
  * @throws \Cake\Network\Exception\NotFoundException When invalid slug is given,
  *  or when upload process could not be completed
  */
 public function upload($name)
 {
     $instance = $this->_getInstance($name);
     require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
     $uploader = new \upload($this->request->data['Filedata']);
     if (!empty($instance->settings['extensions'])) {
         $exts = explode(',', $instance->settings['extensions']);
         $exts = array_map('trim', $exts);
         $exts = array_map('strtolower', $exts);
         if (!in_array(strtolower($uploader->file_src_name_ext), $exts)) {
             $this->_error(__d('field', 'Invalid file extension.'), 501);
         }
     }
     $response = '';
     $uploader->file_overwrite = false;
     $folder = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/");
     $url = normalizePath("/files/{$instance->settings['upload_folder']}/", '/');
     $uploader->process($folder);
     if ($uploader->processed) {
         $response = json_encode(['file_url' => Router::url($url . $uploader->file_dst_name, true), 'file_size' => FileToolbox::bytesToSize($uploader->file_src_size), 'file_name' => $uploader->file_dst_name, 'mime_icon' => FileToolbox::fileIcon($uploader->file_src_mime)]);
     } else {
         $this->_error(__d('field', 'File upload error, details: {0}', $uploader->error), 502);
     }
     $this->viewBuilder()->layout('ajax');
     $this->title(__d('field', 'Upload File'));
     $this->set(compact('response'));
 }
 public function uploadFileImage($file, $ruta, $name)
 {
     if (isset($_FILES[$file]['name'])) {
         if ($_FILES[$file]['name']) {
             $upload = new upload($_FILES[$file], 'es_ES');
             $upload->allowed = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif');
             $upload->file_max_size = '524288';
             // 512KB
             if ($name) {
                 $upload->file_new_name_body = 'upl_' . $name;
             } else {
                 $upload->file_new_name_body = 'upl_' . sha1(uniqid());
             }
             $upload->process($ruta);
             if ($upload->processed) {
                 //THUMBNAILS
                 $imagen = $upload->file_dst_name;
                 $thumb = new upload($upload->file_dst_pathname);
                 $thumb->image_resize = true;
                 $thumb->image_x = 150;
                 $thumb->image_y = 150;
                 //$thumb->file_name_body_pre= 'thumb_';
                 $thumb->process($ruta . 'thumb' . DS);
                 return true;
             } else {
                 throw new Exception('Error al subir la imagen: ' . $upload->error);
             }
         }
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public function updateImage()
 {
     require_once 'helpers/upload.php';
     $code = '';
     if (isset($_POST['id']) && isset($_POST['path'])) {
         $id = intval($_POST['id']);
         $handle = new upload($_FILES['image_field']);
         if ($handle->uploaded) {
             $handle->file_new_name_body = $id;
             $handle->image_resize = true;
             $handle->image_x = 100;
             $handle->image_ratio_y = true;
             $handle->file_overwrite = true;
             $handle->process($_SERVER['DOCUMENT_ROOT'] . '/EduDB/imageUploads/');
             if ($handle->processed) {
                 $handle->clean();
             } else {
                 $_SESSION['ERROR'] = $handle->error;
                 // Failure
             }
         }
         Identity::updateImage($id, '/EduDB/imageUploads/' . $handle->file_dst_name);
     }
     header("Location: " . $_POST['path']);
 }
Exemplo n.º 7
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     if (is_numeric($id)) {
         foreach ($osC_Language->getAll() as $l) {
             $image_upload = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($image_upload->exists() && $image_upload->parse() && $image_upload->save()) {
                 $Qdelete = $osC_Database->query('select image from :table_slide_images where image_id = :image_id and language_id=:language_id');
                 $Qdelete->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qdelete->bindInt(':image_id', $id);
                 $Qdelete->bindValue(':language_id', $l['id']);
                 $Qdelete->execute();
                 if ($Qdelete->numberOfRows() > 0) {
                     @unlink(DIR_FS_CATALOG . 'images/' . $Qdelete->value('image'));
                 }
                 $Qimage = $osC_Database->query('update :table_slide_images set image = :image, description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
                 $Qimage->bindValue(':image', $image_upload->filename);
             } else {
                 $Qimage = $osC_Database->query('update :table_slide_images set description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
             }
             $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
             $Qimage->bindValue(':description', $data['description'][$l['id']]);
             $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
             $Qimage->bindValue(':sort_order', $data['sort_order']);
             $Qimage->bindValue(':status', $data['status']);
             $Qimage->bindInt(':image_id', $id);
             $Qimage->bindValue(':language_id', $l['id']);
             $Qimage->execute();
         }
     } else {
         $Qmaximage = $osC_Database->query('select max(image_id) as image_id from :table_slide_images');
         $Qmaximage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
         $Qmaximage->execute();
         $image_id = $Qmaximage->valueInt('image_id') + 1;
         foreach ($osC_Language->getAll() as $l) {
             $products_image = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($products_image->exists() && $products_image->parse() && $products_image->save()) {
                 $Qimage = $osC_Database->query('insert into :table_slide_images (image_id,language_id ,description,image ,image_url ,sort_order,status) values (:image_id,:language_id,:description ,:image,:image_url ,:sort_order,:status)');
                 $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qimage->bindValue(':image_id', $image_id);
                 $Qimage->bindValue(':language_id', $l['id']);
                 $Qimage->bindValue(':description', $data['description'][$l['id']]);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
                 $Qimage->bindValue(':sort_order', $data['sort_order']);
                 $Qimage->bindValue(':status', $data['status']);
                 $Qimage->execute();
             }
         }
     }
     if ($osC_Database->isError()) {
         return false;
     } else {
         osC_Cache::clear('slide-images');
         return true;
     }
 }
 function storeFileUpload($file, $directory)
 {
     if (is_writeable($directory)) {
         $upload = new upload($file, $directory);
         if ($upload->exists() && $upload->parse() && $upload->save()) {
             return true;
         }
     }
     return false;
 }
 public function nuevo()
 {
     $this->_acl->acceso('Administrador');
     $this->_view->assign('titulo', 'Nueva Aplicación');
     $this->_view->assign('tipo_app', $this->_aplicacion->getTipoApp());
     $this->_view->setJs(array('app'));
     if ($this->getInt('guardar') == 1) {
         $this->_view->assign('datos', $_POST);
         if (!$this->getTexto('nombre')) {
             $this->_view->assign('_error', 'Debe introducir nombre');
             $this->_view->renderizar('nuevo', 'aplicaciones');
             exit;
         }
         if (!$this->getTexto('descp')) {
             $this->_view->assign('_error', 'Debe introducir una descripción');
             $this->_view->renderizar('nuevo', 'aplicaciones');
             exit;
         }
         //Agregar demás verificaciones
         $imagen = '';
         if (isset($_FILES['imagen']['name'])) {
             $this->getLibrary('upload' . DS . 'class.upload');
             $ruta = ROOT . 'public' . DS . 'img' . DS . 'apps' . DS;
             $upload = new upload($_FILES['imagen'], 'es_Es');
             $upload->allowed = array('image/*');
             $upload->file_new_name_body = 'upl_' . uniqid();
             $upload->process($ruta);
             if ($upload->processed) {
                 $imagen = $upload->file_dst_name;
                 $thumb = new upload($upload->file_dst_pathname);
                 $thumb->image_resize = true;
                 $thumb->image_x = 100;
                 $thumb->image_y = 70;
                 $thumb->file_name_body_pre = 'thumb_';
                 $thumb->process($ruta . 'thumb' . DS);
             } else {
                 $this->_view->assign('_error', $upload->error);
                 $this->_view->renderizar('nuevo', 'aplicaciones');
                 exit;
             }
         }
         if ($this->_aplicacion->crearApp($_POST['nombre'], $_POST['descp'], $imagen, $_POST['url'], $_POST['host'], $_POST['usu'], $_POST['clave'], $_POST['nom_bd'], $_POST['puerto'], $_POST['tipo'])) {
             $this->_view->assign('datos', false);
             $this->_view->assign('_confirmacion', 'Conexión exitosa');
             $this->_view->renderizar('nuevo', 'aplicaciones');
             exit;
         } else {
             $this->_view->assign('_confirmacion', 'No se realizo la conexión, verifique los datos');
             $this->_view->renderizar('nuevo', 'aplicaciones');
             exit;
         }
     }
     $this->_view->renderizar('nuevo', 'aplicaciones');
     exit;
 }
Exemplo n.º 10
0
	public function makeThumb() 
	{
		Yii::import('ext.image.class_upload.upload');
		
		$handle = new upload('.'.$this->imgPath.$this->image_name);
		$handle->image_resize            = true;
        $handle->image_ratio_crop        = 'T';
        $handle->image_x                 = 72;
        $handle->image_y                 = 72;
		$handle->process('.'.$this->thumbPath);
	}
Exemplo n.º 11
0
 public function _uploadavatar()
 {
     require_once APPLICATION_PATH . "/lib/avataruploader.php";
     $inputName = 'uploadfile';
     // 即<input type=“file" name="uploadfile" /> 中的name值,不填也行
     $upload = new upload($inputName);
     $new_dir = INDEX_PATH . '/avatar/';
     // 将文件移动到的路径
     $upload->moveTo($new_dir);
     echo "<img src='/avatar/" . $_SESSION["USERID"] . ".jpg' />";
 }
Exemplo n.º 12
0
 public static function getOSSToken()
 {
     $bucket = Yii::app()->params['partner']['oss']['bucket'];
     $domain = Yii::app()->params['partner']['oss']['domain'];
     $id = Yii::app()->params['partner']['oss']['id'];
     $key = Yii::app()->params['partner']['oss']['key'];
     $host = Yii::app()->params['partner']['oss']['host'];
     $oss = new upload($id, $key, $domain);
     $upToken = $oss->uploadToken($bucket);
     return array('uptoken' => $upToken, 'domain' => $domain);
 }
Exemplo n.º 13
0
 public function saveAction()
 {
     $cid = intval($_POST['wid']);
     $name = $_POST['name_cn'];
     $name_en = $_POST['name_en'];
     $type = $_POST['type'];
     $price = $_POST['price'];
     $desc = $_POST['desc'];
     $year = $_POST['years'];
     $active = isset($_POST['active']) && $_POST['active'] == 'on' ? 1 : 0;
     if ($cid) {
         $sql = "Update \n\t\t\t\t\t\t\t`product` \n\t\t\t\t\t\tset \n\t\t\t\t\t\t\t`name_cn`='" . ms($name) . "',\n\t\t\t\t\t\t\t`name_en`='" . ms($name_en) . "',\n\t\t\t\t\t\t\t`price`='" . intval($price) . "',\n\t\t\t\t\t\t\t`years`=" . intval($year) . ",\n\t\t\t\t\t\t\t`desc`='" . ms($desc) . "',\n\t\t\t\t\t\t\t`type`=" . intval($type) . ",\n\t\t\t\t\t\t\t`active`=" . intval($active) . ",\n\t\t\t\t\t\t\t`modify_time`=" . time() . " \n\t\t\t\t\t\twhere \n\t\t\t\t\t\t\t`id`=" . ms($cid);
     } else {
         $sql = "Insert into\n\t\t\t\t\t\t\t `product` (\n\t\t\t\t\t\t\t \t\t`name_cn`,\n\t\t\t\t\t\t\t \t\t`name_en`,\n\t\t\t\t\t\t\t \t\t`price`,\n\t\t\t\t\t\t\t \t\t`years`,\n\t\t\t\t\t\t\t \t\t`desc`,\n\t\t\t\t\t\t\t \t\t`type`,\n\t\t\t\t\t\t\t \t\t`active`,\n\t\t\t\t\t\t\t \t\t`modify_time`) \n\t\t\t\t\t\tValues(\n\t\t\t\t\t\t\t'" . ms($name) . "',\n\t\t\t\t\t\t\t'" . ms($name_en) . "',\n\t\t\t\t\t\t\t'" . ms($price) . "',\n\t\t\t\t\t\t\t'" . ms($year) . "',\n\t\t\t\t\t\t\t'" . ms($desc) . "',\n\t\t\t\t\t\t\t'" . ms($type) . "',\n\t\t\t\t\t\t\t'" . ms($active) . "',\n\t\t\t\t\t\t\t" . time() . "\n\t\t\t\t\t\t)";
     }
     if (DB::query($sql) && !$cid) {
         $b_id = DB::lastInsertID();
     } else {
         if (DB::query($sql) && $cid) {
             $b_id = $cid;
         }
     }
     if (!empty($_FILES)) {
         $order = 1;
         foreach ($_FILES as $i => $v) {
             if (!$v['error']) {
                 $handle1 = new upload($v);
                 if ($handle1->uploaded) {
                     $handle1->file_name_body_pre = '16du_';
                     $handle1->file_new_name_body = $b_id . '_' . $order;
                     //$handle1->file_new_name_ext  = 'png';
                     $handle1->file_overwrite = true;
                     $handle1->file_max_size = '40480000';
                     // $handle1->image_convert = 'png';
                     //$handle1->png_compression = 5;
                     $handle1->process(PRODUCT_SRC . $b_id . '/');
                     if ($handle1->processed) {
                         $sql = "Update `product` set `src" . $order . "` = '" . $handle1->file_dst_name . "' where `id`=" . $b_id;
                         DB::query($sql);
                         $handle1->clean();
                     } else {
                         //echo 'error : ' . $handle1->error;
                     }
                     $order++;
                 }
             }
         }
     }
     $res = new ResultObj(true, '', '保存成功');
     echo $res->toJson();
     exit;
 }
Exemplo n.º 14
0
 function get_upload_file($fld)
 {
     global $UploadCache;
     if (!isset($UploadCache)) {
         $UploadCache = array();
     }
     if (!isset($UploadCache[$fld])) {
         $model_image_obj = new upload($fld);
         $model_image_obj->set_destination(DIR_FS_CATALOG_IMAGES);
         $UploadCache[$fld] = $model_image_obj->parse() && $model_image_obj->save() ? $model_image_obj->filename : '';
     }
     //echo 'get_upload_file('.$fld.")=".$UploadCache[$fld]."\n";
     return $UploadCache[$fld];
 }
Exemplo n.º 15
0
 function upload($file)
 {
     global $_G;
     if (!class_exists('upload')) {
         include ROOT_PATH . 'web/upload.class.php';
     }
     if (!is_array($file)) {
         $file = $this->file;
     }
     $upload = new upload();
     $img_arr = $attach = array();
     $upload_path = '/assets/uploads/';
     $rs = $upload->init($file, $upload_path);
     if (!$rs) {
         return false;
     }
     $attach =& $upload->attach;
     if ($attach['extension'] != 'jpg' && $attach['extension'] != 'png') {
         $this->file_type = '.' . $attach['extension'];
         $this->__construct();
     }
     if ($attach['extension'] == 'attach' && $attach['isimage'] != 1) {
         $this->msg = '上传的文件非图片';
         L($this->msg);
         @unlink($attach['tmp_name']);
         return false;
         //非可上传的文件,就禁止上传了
     }
     $upload_max_size = $_G['setting']['upload_max_size'] ? intval($_G['setting']['upload_max_size']) : 2;
     if ($attach['size'] > 1024 * 1024 * $upload_max_size) {
         $this->msg = '上传文件失败,系统设置最大上传大为:' . $upload_max_size . 'MB';
         L($this->msg);
         @unlink($attach['tmp_name']);
         return false;
     }
     if ($attach['errorcode']) {
         $this->msg = '上传图片失败' . errormessage();
         @unlink($attach['tmp_name']);
         L($this->msg);
         return false;
     }
     $lang_path = ROOT_PATH . $upload_path . $this->dir2;
     if (!is_dir($lang_path)) {
         dmkdir($lang_path);
     }
     $attach['target'] = $lang_path . $this->name;
     $upload->save();
     return $upload_path . $this->dir2 . $this->name;
 }
Exemplo n.º 16
0
 public function saveFile($file)
 {
     $rep_dest = "../var/uploads/";
     $upload = new upload($file);
     $upload->file_overwrite = true;
     //supprime le fichier si existe
     if ($upload->uploaded) {
         //file
         $upload->file_new_name_body = uniqid();
         $upload->Process($rep_dest);
         $upload->clean();
         return $rep_dest . $upload->file_dst_name;
     }
     return null;
 }
Exemplo n.º 17
0
Arquivo: thumbit.php Projeto: soi/paul
function thumb_one($path)
{
    $handle = new upload($path);
    /**********************
       //Create coloured Thumbsnail
       **********************/
    $handle->file_safe_name = false;
    $handle->file_overwrite = true;
    $handle->image_resize = true;
    $handle->image_ratio = true;
    $size = getimagesize($path);
    $factor = $size[0] / $size[1];
    $to_be_cut = abs(round(($size[0] - $size[1]) / 2));
    // determine how far we zoom in for making the thumbnail looking not streched
    if ($factor >= 1) {
        //picture horizontal
        $handle->image_y = 80;
        $handle->image_precrop = "0px " . $to_be_cut . "px";
    } else {
        //picture vertical
        $handle->image_x = 80;
        $handle->image_precrop = $to_be_cut . "px 0px";
    }
    $handle->process('/var/www/web360/html/felix/pics/thumbs/');
    /****************************
       //greyscale thumb (do rarely the same like before)
       *****************************/
    $handle->file_safe_name = false;
    $handle->file_overwrite = true;
    $handle->image_resize = true;
    $handle->image_ratio = true;
    $handle->image_greyscale = true;
    //only difference
    // determine how far we zoom in for making the thumbnail looking not streched
    if ($factor >= 1) {
        //picture horizontal
        $handle->image_y = 80;
        $handle->image_precrop = "0px " . $to_be_cut . "px";
    } else {
        //picture vertical
        $handle->image_x = 80;
        $handle->image_precrop = $to_be_cut . "px 0px";
    }
    $handle->process('/var/www/web360/html/felix/pics/thumbs/bw/');
    if (!$handle->processed) {
        die('error : ' . $handle->error);
    }
}
Exemplo n.º 18
0
 public function action_archivos()
 {
     $errors = array();
     $id = $_GET['contra'];
     $proceso = ORM::factory('gestiones', $id);
     if ($_POST) {
         $id_archivo = 0;
         $archivo_texto = '';
         $post = Validation::factory($_FILES)->rule('archivo', 'Upload::not_empty')->rule('archivo', 'Upload::type', array(':value', array('jpg', 'png', 'gif', 'pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx')))->rule('archivo', 'Upload::size', array(':value', '3M'));
         // ->rules ( 'archivo', array (array ('Upload::valid' ), array ('Upload::type', array (':value', array ('pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx' ) ) ), array ('Upload::size', array (':value', '5M' ) ) ) );
         //si pasa la validacion guardamamos
         if ($post->check()) {
             //guardamos el archivo
             $filename = upload::save($_FILES['archivo1']);
             $archivo1 = ORM::factory('archivos1');
             //intanciamos el modelo
             $archivo1->archivo = basename($filename);
             $archivo1->extension = $_FILES['archivo']['type'];
             $archivo1->size = $_FILES['archivo']['size'];
             $archivo1->fecha = date('Y-m-d');
             $archivo1->proceso_id = $_POST['proceso_id'];
             // $archivo->id = $nuevo->id;
             $archivo->save();
             $_POST = array();
             //enviamos email
             // $this->template->content=View::factory('digitales');
         } else {
             $errors['Datos'] = 'No se pudo guardar, vuelva a intentarlo';
         }
     } else {
         $errors['Archivos'] = 'Ocurrio un error al subir el archivo';
     }
     $archivos = ORM::factory('archivos')->where('proceso_id', '=', $id)->find_all();
     $this->template->content = View::factory('Archivos')->bind('errors', $errors)->bind('proceso', $proceso)->bind('archivos', $archivos);
 }
Exemplo n.º 19
0
 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $original = $model->get($this->name, FALSE);
     // Upload a file?
     if (is_array($value) and upload::valid($value)) {
         if (FALSE !== ($filename = upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace($this->path, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, '/');
             }
             // Delete the old file if we need to
             if ($this->delete_old_file and $original != $this->default) {
                 $path = $this->path . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
Exemplo n.º 20
0
 public function edit($array, $id)
 {
     // if($array['remark'])$array['is_deal'] = 1;
     $img = upload::img('pic1', false);
     $img2 = upload::img('pic2', false);
     if (!empty($img)) {
         $oldInfo = $this->getInfo($id);
         if ($oldInfo['imgurl']) {
             unlink(ROOT_PATH . $oldInfo['imgurl']);
         }
         $array['imgurl'] = $img['url'];
     }
     if (!empty($img2)) {
         $oldInfo = $this->getInfo($id);
         if ($oldInfo['img2url']) {
             unlink(ROOT_PATH . $oldInfo['img2url']);
         }
         $array['img2url'] = $img2['url'];
     }
     // if($array["is_deal"]==1){
     // $array["deal_time"]=date("Y-m-d H:i:s");
     // }else{
     // $array["deal_time"]='null';
     // }
     $this->editData($array, $id);
 }
Exemplo n.º 21
0
 public function __call($function, $args)
 {
     $input = Input::instance();
     $request = new stdClass();
     switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
         case "get":
             $request->params = (object) $input->get();
             break;
         case "post":
             $request->params = (object) $input->post();
             if (isset($_FILES["file"])) {
                 $request->file = upload::save("file");
             }
             break;
     }
     $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
     $request->access_token = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
     $request->url = url::abs_current(true);
     rest::set_active_user($request->access_token);
     $handler_class = "{$function}_rest";
     $handler_method = $request->method;
     if (!method_exists($handler_class, $handler_method)) {
         throw new Rest_Exception("Bad Request", 400);
     }
     try {
         rest::reply(call_user_func(array($handler_class, $handler_method), $request));
     } catch (ORM_Validation_Exception $e) {
         foreach ($e->validation->errors() as $key => $value) {
             $msgs[] = "{$key}: {$value}";
         }
         throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400);
     }
 }
Exemplo n.º 22
0
 function edit()
 {
     $image = clear($_POST['image']);
     if ($_FILES['file']['name']) {
         if ($_POST['image']) {
             unlink($this->pathadm . $_POST['image']);
             unlink($this->pathadm . 'resize/' . $_POST['image']);
         }
         $upload = new upload();
         $upload->process($_FILES['file'], $this->pathadm, $this->max_width);
         $image = clear($upload->name);
     }
     $input = array('name' => clear($_POST['name']), 'alias' => clear($_POST['alias']), 'cha_id' => intval($_POST['cha']), 'cat_id' => intval($_POST['cat']), 'special' => intval($_POST['special']), 'description' => clear($_POST['description']), 'detail' => clear($_POST['detail']), 'image' => $image, 'cards_list' => @implode(',', $_POST['cards']), 'ordering' => (int) $ordering, 'card_slogan' => clear($_POST['card_slogan']));
     $this->db->update_record($this->table, $input, $this->key . '=' . $_GET['id']);
     security::redirect($this->module, 'list');
 }
Exemplo n.º 23
0
 public function insert()
 {
     $msg = array();
     $path = isset($_POST['path']) ? _encrypt($_POST['path'], 'DECODE') : '';
     $size = isset($_POST['size']) ? _encrypt($_POST['size'], 'DECODE') : 0;
     $type = isset($_POST['type']) ? _encrypt($_POST['type'], 'DECODE') : 'image';
     $type = explode(',', $this->getUPtype($type, true));
     $watermark = $_POST['iswatermark'] == "true" ? "yes" : "no";
     if (!is_dir(G_UPLOAD . $path)) {
         $msg['ok'] = 'no';
         $msg['text'] = $path . "文件夹不存在";
         echo json_encode($msg);
         exit;
     }
     System::load_app_class("admin", G_ADMIN_DIR, "no");
     $admincheck = admin::StaticCheckAdminInfo() ? 1 : 0;
     if (is_array($_FILES['Filedata'])) {
         System::load_sys_class('upload', 'sys', 'no');
         upload::upload_config($type, $size, $path);
         upload::go_upload($_FILES['Filedata'], $watermark);
         if (!upload::$ok) {
             $msg['ok'] = 'no';
             $msg['text'] = upload::$error;
         } else {
             $msg['ok'] = 'yes';
             $msg['text'] = $path . '/' . upload::$filedir . "/" . upload::$filename;
         }
         echo json_encode($msg);
     }
 }
Exemplo n.º 24
0
 public function action_index()
 {
     if ($_POST) {
         try {
             foreach ($_POST['option'] as $option_id => $value) {
                 $option = ORM::factory('Option', $option_id);
                 $option->value = $value;
                 $option->save();
             }
             if (arr::get($_FILES, 'option', false)) {
                 foreach ($_FILES['option']['name'] as $key => $file) {
                     $ext = $_FILES['option']['name'][$key];
                     $ext = explode('.', $ext);
                     $ext = end($ext);
                     $filename = upload::save(array('name' => $_FILES['option']['name'][$key], 'type' => $_FILES['option']['type'][$key], 'tmp_name' => $_FILES['option']['tmp_name'][$key], 'error' => $_FILES['option']['error'][$key], 'size' => $_FILES['option']['size'][$key]), 'option-' . $key . '.' . $ext, 'media/uploads');
                     $option = ORM::factory('Option', $key);
                     $option->value = 'option-' . $key . '.' . $ext;
                     $option->save();
                 }
             }
             ajax::success(__('Settings saved'));
         } catch (ORM_Validation_Exception $e) {
             ajax::error(__('An error occured and the settings couldn\'t be saved: :error', array(':error' => $e->getMessage())));
         }
     }
 }
Exemplo n.º 25
0
 public function saveupload()
 {
     $json = new Services_JSON();
     $uploadpath = 'upload/goods/';
     $filepath = '/upload/goods/';
     $upload = new upload($uploadpath, array('gif', 'jpg', 'jpge', 'png'));
     //upload
     $file = $upload->getfile();
     if ($upload->errno != 15 && $upload->errno != 0) {
         $msg = $json->encode(array('error' => 1, 'message' => $upload->errmsg()));
     } else {
         $msg = $json->encode(array('error' => 0, 'url' => $filepath . $file[0][saveName], 'trueurl' => $upload->returninfo['name']));
     }
     echo $msg;
     exit;
 }
Exemplo n.º 26
0
 public function postSave()
 {
     $modified = $this->getModified(FALSE, TRUE);
     if ((array_key_exists('description', $modified) or array_key_exists('name', $modified)) and !$this->skip_desc_propagate) {
         $resampled = $this->get_resampled();
         foreach ($resampled as $key => $mediafile) {
             $differs = FALSE;
             if ($this->get('mediafile_id') == $mediafile['mediafile_id']) {
                 continue;
             }
             if ($this->get('description') != $mediafile['description']) {
                 $differs = TRUE;
                 $resampled[$key]['description'] = $this->get('description');
             }
             if ($this->get('name') != $mediafile['name']) {
                 $differs = TRUE;
                 $resampled[$key]['name'] = $this->get('name');
             }
             if (!$differs) {
                 continue;
             }
             kohana::log('debug', 'Copy media file description or name from ' . $this->get('mediafile_id') . ' to ' . $mediafile['mediafile_id']);
             $mediafile->skip_desc_propagate = TRUE;
             $resampled[$key]->save();
             $mediafile->skip_desc_propagate = FALSE;
         }
     }
     if (!$this->uploaded_file) {
         return;
     }
     kohana::log('debug', 'Moving upload "' . $this->uploaded_file['tmp_name'] . '" to "' . $this->filepath(TRUE) . '"');
     if (!upload::save($this->uploaded_file, $this->get('file'), $this->filepath())) {
         throw new Exception('Unable to save file to system');
     }
 }
Exemplo n.º 27
0
 public function upimage()
 {
     //System::load_app_class('Uploader','','no');
     //上传图片框中的描述表单名称,
     //$title = htmlspecialchars($_POST['pictitle'], ENT_QUOTES);
     //$path = htmlspecialchars($_POST['dir'], ENT_QUOTES);
     if (!isset($_POST['pictitle']) && !isset($_FILES['upfile'])) {
         exit;
     }
     $title = $_POST['pictitle'];
     $path = G_UPLOAD . 'shopimg/';
     System::load_sys_class('upload', 'sys', 'no');
     upload::upload_config(array('png', 'jpg', 'jpeg', 'gif'), 500000, 'shopimg');
     upload::go_upload($_FILES['upfile']);
     if (!upload::$ok) {
         $url = '';
         $title = $title;
         $originalName = '';
         $state = upload::$error;
     } else {
         $url = G_UPLOAD_PATH . '/shopimg/' . upload::$filedir . "/" . upload::$filename;
         $title = $title;
         $originalName = '';
         $state = 'SUCCESS';
     }
     echo "{'url':'" . $url . "','title':'" . $title . "','original':'" . $originalName . "','state':'" . $state . "'}";
     //{'url':'upload/20130728/13749880933714.jpg','title':'梨花.jpg','original':'梨花.jpg','state':'SUCCESS'}
 }
Exemplo n.º 28
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
Exemplo n.º 29
0
 /** 
  * Upload function for a JNCC style designations spreadsheet.
  */
 public function upload_csv()
 {
     try {
         // We will be using a POST array to send data, and presumably a FILES array for the
         // media.
         // Upload size
         $ups = Kohana::config('indicia.maxUploadSize');
         $_FILES = Validation::factory($_FILES)->add_rules('csv_upload', 'upload::valid', 'upload::required', 'upload::type[csv]', "upload::size[{$ups}]");
         if (count($_FILES) === 0) {
             echo "No file was uploaded.";
         } elseif ($_FILES->validate()) {
             if (array_key_exists('name_is_guid', $_POST) && $_POST['name_is_guid'] == 'true') {
                 $finalName = strtolower($_FILES['csv_upload']['name']);
             } else {
                 $finalName = time() . strtolower($_FILES['csv_upload']['name']);
             }
             $fTmp = upload::save('csv_upload', $finalName);
             url::redirect('taxon_designation/import_progress?file=' . urlencode(basename($fTmp)));
         } else {
             kohana::log('error', 'Validation errors uploading file ' . $_FILES['csv_upload']['name']);
             kohana::log('error', print_r($_FILES->errors('form_error_messages'), true));
             throw new ValidationError('Validation error', 2004, $_FILES->errors('form_error_messages'));
         }
     } catch (Exception $e) {
         $this->handle_error($e);
     }
 }
Exemplo n.º 30
0
 public function insert()
 {
     $msg = array();
     $path = isset($_POST['path']) ? _encrypt($_POST['path'], 'DECODE') : '';
     $size = isset($_POST['size']) ? _encrypt($_POST['size'], 'DECODE') : 0;
     $type = isset($_POST['type']) ? _encrypt($_POST['type'], 'DECODE') : 'image';
     $type = explode(',', $this->getUPtype($type, true));
     if (!is_dir(G_UPLOAD . $path)) {
         $msg['ok'] = 'no';
         $msg['text'] = $path . "文件夹不存在";
         echo json_encode($msg);
         exit;
     }
     if (is_array($_FILES['Filedata'])) {
         System::load_sys_class('upload', 'sys', 'no');
         upload::upload_config($type, $size, $path);
         upload::go_upload($_FILES['Filedata']);
         if (!upload::$ok) {
             $msg['ok'] = 'no';
             $msg['text'] = upload::$error;
         } else {
             $msg['ok'] = 'yes';
             $msg['text'] = $path . '/' . upload::$filedir . "/" . upload::$filename;
         }
         echo json_encode($msg);
     }
 }