Exemple #1
0
 public function uploadFoto($directory, $arquivo, $nomeArquivo, $tamanhos = array(), $cropValues = array())
 {
     $this->caminho = BASEPATH . UPLOADPATH . '/' . $directory;
     $this->tamanhos = $tamanhos;
     if (empty($arquivo)) {
         $this->nomeArquivoFoto = $nomeArquivo;
         return false;
     }
     $directory = ltrim(rtrim($directory));
     if (!is_dir($this->caminho)) {
         mkdir($this->caminho);
     }
     if (is_dir($this->caminho)) {
         $destinoOriginal = $this->caminho . '/';
         if (!is_dir($destinoOriginal)) {
             mkdir($destinoOriginal);
         }
         $path_parts = pathinfo($nomeArquivo);
         $nomeArquivo = $path_parts['filename'];
         $upload = new upload($arquivo, $destinoOriginal, $nomeArquivo);
         if ($upload->getError() == false) {
             $origem = $destinoOriginal . $upload->getArquivo();
             foreach ($this->tamanhos as $tamanho => $valores) {
                 $_destCrop = 'destino_' . $tamanho;
                 ${$_destCrop} = $this->caminho . '/' . $tamanho . '/';
                 if (!is_dir(${$_destCrop})) {
                     mkdir(${$_destCrop});
                 }
                 ${$_destCrop} = ${$_destCrop} . $upload->getArquivo();
                 $w = $cropValues['w'];
                 $h = $cropValues['h'];
                 $x1 = $cropValues['x1'];
                 $y1 = $cropValues['y1'];
                 $crop = new crop_image();
                 $crop->setImage($origem, ${$_destCrop}, $w, $h, $x1, $y1, $valores['w'], $valores['h']);
                 $crop->cropResize();
             }
             $this->nomeArquivoFoto = $upload->getArquivo();
             return true;
         } else {
             throw new Exception($upload->getError(), 1);
         }
     } else {
         throw new Exception('Erro ao efetuar o upload. O diretório não existe', 1);
     }
 }
Exemple #2
0
 /**
  * faz o upload do arquivo
  * @return boolean, String
  */
 public function uploadFoto($nomeArquivo, $arquivo)
 {
     //verifica se o diretório existe
     if (is_dir(BASEPATH . 'skin/uploads/produtos/')) {
         $destino = BASEPATH . 'skin/uploads/produtos/';
         $destino_p = BASEPATH . 'skin/uploads/produtos/p/';
         if (!is_dir($destino)) {
             mkdir($destino);
         }
         if (!is_dir($destino_p)) {
             mkdir($destino_p);
         }
         $img = new upload($arquivo, $destino, $nomeArquivo);
         if ($img->getError() == false) {
             $dest = $destino . $img->getArquivo();
             $dest_p = $destino_p . $img->getArquivo();
             if (isset($_POST['w']) && $_POST['w'] != '' || isset($_POST['h']) && $_POST['h'] != '' || isset($_POST['x1']) && $_POST['x1'] != '' || isset($_POST['y1']) && $_POST['y1'] != '') {
                 $w = $_POST['w'];
                 $h = $_POST['h'];
                 $x1 = $_POST['x1'];
                 $y1 = $_POST['y1'];
                 $crop = new crop_image();
                 $crop->setImage($dest, $dest_p, $w, $h, $x1, $y1, 404, 158);
                 $crop->cropResize();
                 $crop->setImage($dest, $dest, $w, $h, $x1, $y1, 1349, 527);
                 $crop->cropResize();
             } else {
                 $w = $_POST['w'];
                 $h = $_POST['h'];
                 $x1 = $_POST['x1'];
                 $y1 = $_POST['y1'];
                 $crop = new crop_image();
                 $crop->setImage($dest, $dest_p, $w, $h, $x1, $y1, 404, 158);
                 $crop->setImage($dest, $dest, $w, $h, $x1, $y1, 1349, 527);
                 $crop->resize();
             }
             $this->nomeArquivoFoto = $img->getArquivo();
             return true;
         } else {
             return $img->getError();
         }
     } else {
         return 'Erro ao efetuar o upload. O diretório não existe';
     }
 }