%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home1/dimen328/libertysa.com.br/admin/includes/
Upload File :
Create Path :
Current File : //home1/dimen328/libertysa.com.br/admin/includes/uploader.php

<?php	

	class Uploader {

		private $arquivo;
		private $maxSize = 50000000;
		private $diretorioDestino = "uploads/";
		private $extensoesImagem = Array("jpg", "jpeg", "png", "gif");
		private $extensoesVideo = Array("wmv", "mp4", "avi");

		private $retorno;
		private $mensagem;
		private $arquivoEnviado;

		public function __construct() {
			$this->arquivo = Array();
			foreach ($_FILES as $inputname => $file) {
				$this->arquivo[$inputname] = (object) $file;
			}
		}

		public function getMensagem() {
			return $this->mensagem;
		}

		public function getArquivoEnviado() {
			return $this->arquivoEnviado;
		}

		public function getRetorno() {
			return $this->retorno;
		}

		public function setDiretorio($diretorio) {
			$this->diretorioDestino = $diretorio;
		}

		public function getDiretorio() {
			return $this->diretorioDestino;
		}

		public function setMaxSizeMB($max) {
			$this->maxSize = $max * 1000000;
		}

		public function enviarImagem($arquivo) {
			if ($this->verificaArquivo($arquivo)) {
				$arquivoDestino = $this->diretorioDestino . basename($this->arquivo[$arquivo]->name);
				$extensaoArquivo = pathinfo($arquivoDestino, PATHINFO_EXTENSION);			

				// Check if image file is a actual image or fake image
				$check = getimagesize($this->arquivo[$arquivo]->tmp_name);
				if($check === false) {
					$this->retorno = 0; //file is not an image
					$this->mensagem = 'Arquivo não é uma imagem';
				} else {
					// Generate a new random filename if file already exists
					while (file_exists($arquivoDestino)) {
						$arquivoDestino = $this->diretorioDestino . $this->randomKey(15) . '.' . $extensaoArquivo;
					}	

					// Check file size
					if ($this->arquivo[$arquivo]->size > $this->maxSize) {
						$this->retorno = -1;
						$this->mensagem = 'Arquivo excedeu o tamanho limite';
					} else {						
						// Allow certain file formats
						if(!in_array($extensaoArquivo, $this->extensoesImagem)) {
							$this->retorno = -2;
							$this->mensagem = 'Extensão de arquivo invalida';
						} else {
							// if everything is ok, try to upload file
							if (move_uploaded_file($this->arquivo[$arquivo]->tmp_name, $arquivoDestino)) {
								$this->retorno = 1;
								$this->mensagem = 'Sucesso';
							} else {
								$this->retorno = -3;
								$this->mensagem = 'Erro ao gravar arquivo';
							}							
						}			
					}		
				}
			} else {
				$this->retorno = -4;
				$this->mensagem = 'Erro ao realizar upload';
			}

		}

		public function enviarVideo($arquivo) {
			if ($this->verificaArquivo($arquivo)) {
				$arquivoDestino = $this->diretorioDestino . basename($this->arquivo[$arquivo]->name);
				$extensaoArquivo = pathinfo($arquivoDestino, PATHINFO_EXTENSION);			

				// Generate a new random filename
				do {
				    $newName = $this->randomKey2() . '.'. $extensaoArquivo;
					$arquivoDestino = $this->diretorioDestino . $newName  ;
				} while (file_exists($arquivoDestino));

				// Check file size
				if ($this->arquivo[$arquivo]->size > $this->maxSize) {
					$this->retorno = -1;
					$this->mensagem = 'Arquivo excedeu o tamanho limite';
				} else {						
					// Allow certain file formats
					if(!in_array($extensaoArquivo, $this->extensoesVideo)) {
						$this->retorno = -2;
						$this->mensagem = 'Extensão de arquivo invalida';
					} else {
						// if everything is ok, try to upload file
						if (@move_uploaded_file($this->arquivo[$arquivo]->tmp_name, $arquivoDestino)) {
							$this->retorno = 1;
							$this->mensagem = 'Successo';
							$this->arquivoEnviado = $newName;
						} else {
							$this->retorno = -3;
							$this->mensagem = 'Erro ao gravar o arquivo';
							$this->arquivoEnviado = '';
						}							
					}			
				}		
			} else {
				$this->retorno = 0;
				$this->mensagem = 'Erro ao realizar upload';
			}

		}

		private function verificaArquivo($arquivo) {
			$retorno = false;
			if (isset($this->arquivo[$arquivo]) && ($this->arquivo[$arquivo]->error === UPLOAD_ERR_OK)) {
				$retorno = true;
			}
			return $retorno;
		}

		private function randomKey($length = 15) {
			$pool = array_merge(range(0,9), range('a', 'z'),range('A', 'Z'));
			$key = "";
			for($i=0; $i < $length; $i++) {
				$key .= $pool[mt_rand(0, count($pool) - 1)];
			}
			return $key;
		}

		private function randomKey2() {
			return md5(time());
		}

	}
?>

Zerion Mini Shell 1.0