D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
adms
/
Models
/
helper
/
Filename :
AdmsUploadImgSimples_ant.php
back
Copy
<?php namespace App\adms\Models\helper; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of AdmsUploadImgSimples * * @copyright (c) year, Cesar Szpak - Celke */ class AdmsUploadImgSimples { private $DadosImagem; private $Diretorio; private $NomeImg; private $Tipo; private $Tamanho; private $Resultado; private $Imagem; private $erros; private $msg; function getResultado() { return $this->Resultado; } public function uploadImagem(array $Imagem, $Diretorio, $NomeImg ) { $this->DadosImagem = $Imagem; $this->Diretorio = $Diretorio; $this->NomeImg = $NomeImg; $this->Imagem = $this->DadosImagem['tmp_name']; $this->Tipo = $this->DadosImagem['type']; $this->Tamanho = $this->DadosImagem['size']; $this->validarImagem(); if($this->Resultado){ $this->valDiretorio(); }else{ if(!empty($this->erros)){ $_SESSION['msg'] =""; foreach ($this->erros as $erro) $this->msg .= $erro; } $_SESSION['msg'] ="<div class='alert alert-danger' role='alert' >". $this->msg ." <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true' >×</span> </button> </div>"; } return $this->Resultado; } private function validarImagem() { $this->erros = array(); $this->Resultado = true; $arquivos_permitidos = ['mp4','jpg', 'png', 'jpeg']; //$arquivos_permitidos = [ 'pn ', 'jpe ']; $extensao = pathinfo($this->NomeImg, PATHINFO_EXTENSION); if(!in_array($extensao, $arquivos_permitidos)){ $this->erros[] = "Extensão ". $extensao. " não permitida !!"; $this->Resultado = false; } $tipo_permitidos = ['video/mp4','image/jpg', 'image/png', 'image/jpeg']; // $tipo_permitidos = ['image/jp', 'image/pn']; if(!in_array($this->Tipo, $tipo_permitidos)){ $this->erros[] = " <br>Tipo ". $this->Tipo. " não permitido !!"; $this->Resultado = false; } //$tamanho_maximo = (1024); //5MB $tamanho_maximo = (1024 * 1024 * 7); //5MB if($this->Tamanho > $tamanho_maximo){ $this->erros[] = " <br>Tamanho de ". $this->Tamanho. " maior que 5MB !!"; $this->Resultado = false; } } private function valDiretorio() { if(!file_exists($this->Diretorio) && !is_dir($this->Diretorio)){ mkdir($this->Diretorio, 0755); } $this->realizarUpload(); } private function realizarUpload() { if(move_uploaded_file($this->DadosImagem['tmp_name'], $this->Diretorio . $this->NomeImg)){ $this->Resultado = true; }else{ $_SESSION['msg'] = "<div class='alert alert-danger'>Erro: Não conseguiu realizar o upload da imagem!</div>"; $this->Resultado = false; } } }