/**
* @author espiritodocoracao@hotmail.com
* @copyright 2008
*/
class Upload{
public $w;
public $h;
public $dir;
public $type;
public $file;
public $resize;
public $rename;
public $files;
public $msg_error;
public $peso;
public $peso_msg;
public $ext_msg;
public $ext;
protected $error;
protected $image;
protected $tipo;
protected $filetype;
protected $upload;
protected $width_orig;
protected $height_orig;
protected $imagem;
protected $imagem_p;
protected $methodCreateFrom;
protected $typefile;
protected $rename_2;
protected $imagetype;
protected $upa;
protected $up;
protected $pesofile;
protected $ext_allow;
/** metodo construct faz a verificacao do tipo de arquivo */
public function __construct($file){
$files = $_FILES["$file"];
$this->filetype = $files['type'];
$tipo = explode("/",$this->filetype);
if($tipo['0'] == 'image'){
switch($tipo['1']){
case "jpeg":
$this->image = "jpeg";
$this->methodCreateFrom = "imagecreatefromjpeg";
$this->imagetype = "imagejpeg";
break;
case "gif":
$this->image = 'gif';
$this->methodCreateFrom = "imagecreatefromgif";
$this->imagetype = "imagegif";
break;
case "png": $image = "png";
$this->methodCreateFrom = "imagecreatefrompng";
$this->imagetype = "imagepng";
break;
}
return $this->image;
return $this->imagetype;
return $this->methodCreateFrom;
}
return $tipo['1'];
return $tipo['0'];
}
/** metodo para setar o diretorio de destino */
public function setDir($dir){
if(!is_dir($dir)){
$dire = mkdir($dir);
if(!$dire){
echo "Diretorio setado inexiste/permissao negada para criacao!";
}else{
$this->dir = $dir;
return $this->dir;
}
}
}
/** metodo para setar a largura em caso de redimensionamento */
public function setW($w){
$this->w = $w;
return $this->w;
}
/** metodo para setar a altura em caso de redimensionamento */
public function setH($h){
$this->h = $h;
return $this->h;
}
/** metodo para setar o redimensionamento */
public function setRezise($resize = false){
return $this->resize;
}
/** metodo de validacao das extensoes permitidas */
public function setExtAllowed($ext){
$this->type = explode("/",$this->files['type']);
if(is_array($ext)){
if(in_array($this->tipo['1'],$ext)){
$this->ext_allow = true;
$this->ext_msg = '';
}else{
$this->ext_allow = false;
$this->ext_msg = "Extensao de arquivo nao permitido";
}
}else{
if($ext == $this->type['1']){
$this->ext_allow = true;
$this->ext_allow = '';
}else{
$this->ext_allow = false;
$this->ext_msg = "Extensao de arquivo nao permitido";
}
}
return $this->ext_allow;
return $this->ext_msg;
}
/** metodo para renomear o arquivo*/
public function Rename($rename = 0){
// 0 => name
// 1 => date
// 2 => thumb_name
// 3 => thumb_date
// 4 => uniq
$typefile = explode(".",$this->files);
switch($this->rename){
case '0': $this->rename_2 = implode(".",$this->typefile);
break;
case '1': $this->rename_2 = date("d_m_Y_H_i_s").".".$this->typefile['1'];
break;
case '2': $this->rename_2 = "thumb_".$this->typefile['0'].".".$this->typefile['1'];
break;
case '3': $this->rename_2 = "thumb_".date("d_m_Y_H_i_s").".".$this->typefile['1'];
break;
case '4': $this->rename_2 = uniqid(md5($this->typefile['0'])).".".$this->typefile['1'];
break;
}
return $this->rename_2;
}
/** metodo de validacao do envio do upload */
public function setMsg(){
$this->error = $this->files['error'];
switch($this->error){
case UPLOAD_ERR_OK: $this->msg_error = "Upload feito com sucesso!";
break;
case UPLOAD_ERR_INI_SIZE: $this->msg_error = "Arquivo maior que o especificado!";
break;
case UPLOAD_ERR_FORM_SIZE: $this->msg_error = "Arquivo maior que o especificado pelo formulario!";
break;
case UPLOAD_ERR_PARTIAL: $this->msg_error = "Upload realizado parcialmente!";
break;
case UPLOAD_ERR_NO_FILE: $this->msg_error = "Sem arquivo definido para upload!";
break;
}
return $this->msg_error;
}
/** metodo de validacao do tamanho do arquivo */
public function setPeso($peso){
if($files['size'] > $peso){
$this->pesofile = false;
$this->peso_msg = "Peso acima do permitido!";
}else{
$this->pesofile = true;
$this->peso_msg = "";
}
return $this->pesofile;
return $this->peso_msg;
}
/** metodo para fazer o upload, utilizando as validacoes */
public function Execute(){
/** se ha arquivo */
if($_FILES){
/** valida o tamanho */
if(self::setPeso($this->files['name'])){
/** valida as extensoes permitidas */
if(self::setExtAllowed($ext)){
/** verifica se eh uma imagem */
if($this->image == "image"){
/** se foi setado para redimensionar a imagem */
if($this->resize == true){
/** redimensiona */
list($width_orig, $height_orig) = getimagesize($this->files['tmp_name']);
if ($this->w && ($width_orig < $height_orig)) {
$this->w = ($this->h / $height_orig) * $width_orig;
} else {
$this->h = ($this->w / $width_orig) * $height_orig;
}
$imagem_p = imagecreatetruecolor($this->w, $this->h);
$imagem = $this->methodCreateFrom($this->files);
imagecopyresampled($imagem_p, $imagem, 0, 0, 0, 0, $this->w, $this->h, $width_orig, $height_orig);
/** upa a imagem redimensionada */
$upa = $this->imagetype($imagem_p, $this->dir."/".$this->rename_2, 100);
if($upa){
/** se upou emite a mensagem */
echo self::setMsg();
}else{
/** se nao upou emite a mensagem */
echo self::setMsg();
}
/** se nao foi setado para redimensionar a imagem, ou seja, enviar do jeito que e */
}else{
/** valida o tamanho em kb */
if(self::setPeso($this->files['name'])){
/** valida as extensoes */
if(self::setExtAllowed($ext)){
/** upa o arquivo */
$upa = move_uploaded_file($this->files['tmp_name'], $this->dir."/".$this->rename_2);
if($upa){
/** se upou emite a mensagem */
echo self::setMsg();
}else{
/** se nao upou */
echo self::setMsg();
}
}
}
}
/** se nao for imagem */
}else{
/** valida a extensao */
if(self::setExtAllowed($ext)){
/** valida o tamanho em kb */
if(self::setPeso($this->files['name'])){
/** upa o arquivo */
$upa = move_uploaded_file($files['tmp_name'],$this->dir."/".$this->rename_2);
if($upa){
/** se upou emite a mensagem */
echo self::setMsg();
}else{
/** se nao upou */
echo self::setMsg();
}
}else{
echo $this->peso_msg;
}
}
}
}
}
}
}
}
?>
acabei de criar esta classe, mas nao esta funcionando, nem emitindo mensagem de erro...
como resolver...?

Help














