Beispiel #1
0
 /**
  * Method to handle file upload thought XHR2
  * On success returns JSON object with image info.
  * @param $album_foto_id string Gallery Id to upload images
  * @throws CHttpException
  */
 public function actionAjaxUpload($album_foto_id = null)
 {
     $album_foto = AlbumFoto::model()->findByPk($album_foto_id);
     $imageFile = CUploadedFile::getInstanceByName('image');
     $time = time() + rand();
     $base = Yii::getPathOfAlias('webroot') . '/' . $this->galleryDir . '/' . $album_foto->directorio;
     $src = $time . '.' . $this->galleryExt;
     $thumb = $time . '_thumb.' . $this->galleryExt;
     $image = new Image($imageFile->getTempName());
     $image->save($base . $src);
     $image_thumb = new Image($imageFile->getTempName());
     $image_thumb->resize(300, null);
     $image_thumb->save($base . $thumb);
     //Yii::app()->image->load($imageFile->getTempName())->save($src);
     //Yii::app()->image->load($imageFile->getTempName())->resize(300, null)->save($thumb);
     $model = new Foto();
     $model->album_foto_id = $album_foto_id;
     $url = new Url();
     $slug = '#imagenes/' . $this->slugger($album_foto->nombre) . '/' . $this->slugger($time);
     $slug = $this->verificarSlug($slug);
     $url->slug = $slug;
     $url->tipo_id = 6;
     //Foto
     $url->estado = 1;
     $url->save();
     $model->url_id = $url->getPrimaryKey();
     $model->src = $src;
     $model->thumb = $thumb;
     $model->nombre = $time;
     $model->descripcion = '';
     $model->ancho = $image->width;
     $model->alto = $image->height;
     $model->orden = 0;
     $model->estado = 1;
     $model->destacado = 0;
     $model->save();
     header("Content-Type: application/json");
     echo CJSON::encode(array('id' => $model->id, 'rank' => $model->orden, 'name' => (string) $model->nombre, 'description' => (string) $model->descripcion, 'preview' => bu($this->galleryDir . '/' . $album_foto->directorio . $thumb)));
 }
Beispiel #2
0
 //print_r($_POST);
 if (!empty($_FILES)) {
     foreach ($_FILES as $key => $file) {
         if ($file['error'] != 4) {
             $foto = new Foto();
             if ($foto->attach_file($file)) {
                 $foto->idApartament = $idApartament;
                 $detalii = "Detalii" . $key;
                 $foto->Detalii = ${$detalii};
                 $ordin = "Ordin" . $key;
                 $foto->Ordin = ${$ordin};
                 $schita = "Schita" . $key;
                 $foto->Schita = ${$schita};
                 $privat = "Privat" . $key;
                 $foto->Privat = ${$privat};
                 if ($foto->save()) {
                     $message .= "";
                 } else {
                     foreach ($foto->errors as $error) {
                         $message .= $error . "(" . $file['name'] . ");";
                     }
                 }
             } else {
                 foreach ($foto->errors as $error) {
                     $message .= $error . "(" . $file['name'] . ");";
                 }
             }
         }
     }
 }
 $oferta = Oferta::find_by_id($idOferta);
 public function actionCrear()
 {
     // $file=$_FILES["file"]["name"];
     // if(!is_dir ("files/"))
     // 	mkdir("files/", 0777);
     // if($file && move_uploaded_file($_FILES["file"]["tmp_name"],"files/".$file))
     // {
     // 	$this->sendResponse("OK");
     // }
     if (isset($_FILES['file']['name'])) {
         $file_name = $_FILES["file"]["name"];
         $base_path = realpath(Yii::app()->getBasePath() . '/../img/galeria');
         $path = $base_path . "/" . $file_name;
         //$this->sendResponse($base_path, 500);
         if (!is_dir($base_path)) {
             mkdir($base_path, 0777);
         }
         if ($file_name && move_uploaded_file($_FILES["file"]["tmp_name"], $path)) {
             $fotoModel = new Foto();
             $fotoModel->titulo = $_POST['name'];
             $fotoModel->link = Yii::app()->getBaseUrl() . "/img/galeria/" . $file_name;
             if ($fotoModel->save()) {
                 $this->sendResponse($fotoModel);
             } else {
                 $this->sendResponse("No se pudo guardar el modelo", 500);
             }
         } else {
             $this->sendResponse("No se pudo guardar el archivo", 500);
         }
     }
     //parent::actionCrear();
 }
Beispiel #4
0
 private function subirFotoUsuario($idcategoria, $field, $nombre, $idfoto = null)
 {
     $foto = new Foto($idfoto);
     $categoria = new CategoriaNoticia($idcategoria);
     $config['upload_path'] = './fotos/usuarios/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = '2048';
     $config['max_width'] = '2048';
     $config['max_height'] = '2048';
     $config['file_name'] = $nombre;
     $this->load->library('upload', $config);
     if ($this->upload->do_upload($field)) {
         $datos = $this->upload->data();
         $foto->ruta = 'fotos/usuarios/' . $datos['file_name'];
         $foto->ancho = $datos['image_width'];
         $foto->alto = $datos['image_height'];
         $foto->tamano = $datos['file_size'];
         $foto->nombre = $nombre;
         $foto->save();
     } else {
         //TODO: Comprobar si ha fallado algo, borrar si ha fallado, no borrar si no se ha introducido nada.
         //$foto->delete();
     }
     return $foto;
 }
Beispiel #5
0
<?php

require_once "../model/foto.php";
$img = new Foto();
$ft = $_FILES['file_upload'];
if (isset($ft)) {
    if ($img->enviar_arquivo($ft)) {
        if ($img->save()) {
            header("location: ../view.php");
        } else {
            echo "Erro ao salvar imagem.<br>";
            print_r($img->errors);
            header("location: ../view/index.php");
        }
    } else {
        header("location: ../view/index.php");
    }
}
 public function postGaleria()
 {
     $categoria = Input::get('categorias_id');
     $mes = Input::get('mes');
     $ano = Input::get('ano');
     $imagens = Input::file('file');
     if (isset($imagens) && sizeof($imagens)) {
         foreach ($imagens as $image) {
             $categoria = Input::get('categorias_id');
             $mes = Input::get('mes');
             $imageNome = $image->getClientOriginalName();
             $pasta = public_path() . '/assets/empreendimentos/fotos/';
             $upload_success = Image::make($image->getRealPath())->resize(600, null, function ($constraint) {
                 $constraint->aspectRatio();
             })->save(public_path() . '/assets/empreendimentos/fotos/' . $ano . '_' . $mes . '_' . $categoria . '_' . $imageNome);
             if ($upload_success) {
                 $dataFormatada = $ano . '-' . $mes . '-' . date('d');
                 $img = new Foto();
                 $img->categorias_id = $categoria;
                 $img->mes = $dataFormatada;
                 $img->imagem = '/assets/empreendimentos/fotos/' . $ano . '_' . $mes . '_' . $categoria . '_' . $imageNome;
                 $img->save();
                 Session::flash('message', 'As fotos foram salvas com sucesso.');
             } else {
                 Session::flash('message', 'Erro ao cadastrar as fotos!');
             }
         }
         return Redirect::to('admin/empreendimento/editar-galeria-de-fotos/' . $categoria);
     }
 }