Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/01/2013, 13:42
underwebinfo
 
Fecha de Ingreso: septiembre-2012
Ubicación: Buenos aires
Mensajes: 110
Antigüedad: 11 años, 7 meses
Puntos: 9
in_array inconvenientes en una clase

Hola que tal, estaba haciendo una clase para subir archivos en php, y me encuentro con un pequeño problema en la funcion in_array [cosa que me esta volviendo dezquisiado].

La clase es esta:
Código PHP:
Ver original
  1. # Upload
  2.     class Cm_Upload{
  3.        
  4.         # Forma de uso
  5.         # $Upload->UploadConfig($Name,$Path);
  6.         # $Upload->_Type();
  7.         # $Upload->_MinSize();
  8.         # $Upload->_MaxSize();
  9.         # $Upload->_UploadSave();
  10.        
  11.         # Configuracion
  12.         protected   $_Name      = NULL;
  13.         protected   $_Path      = NULL;
  14.         private     $_Type      = NULL;
  15.         private     $_MinSize   = NULL;
  16.         private     $_MaxSize   = NULL;
  17.        
  18.         # Privates & Condicionales
  19.         private     $_Extencion = NULL;
  20.        
  21.         # Constructor
  22.         public function UploadConfig($Name,$Path){
  23.            
  24.             $this->_Name        = $Name;
  25.             $this->_Path        = $Path;
  26.            
  27.         }
  28.        
  29.         # Convertor Bytes
  30.         private function _ConvertBytes($size){
  31.             if (is_int($size) || ctype_digit($size)) {
  32.                 return (int) $size;
  33.             }
  34.    
  35.             $tipo = strtolower(substr($size, -1));
  36.             $size = (int) $size;
  37.    
  38.             switch ($tipo) {
  39.                 case 'g': //Gigabytes
  40.                     $size *= 1073741824;
  41.                     break;
  42.                 case 'm': //Megabytes
  43.                     $size *= 1048576;
  44.                     break;
  45.                 case 'k': //Kilobytes
  46.                     $size *= 1024;
  47.                     break;
  48.                 default :
  49.                     $size = -1;
  50.                    
  51.             }
  52.    
  53.             return $size;
  54.         }
  55.        
  56.         # MinSize
  57.         public function _MinSize($int){
  58.             $this->_MinSize = $this->_ConvertBytes($int);
  59.            
  60.         }
  61.        
  62.         # MaxSize
  63.         public function _MaxSize($int){
  64.            
  65.             $this->_MaxSize = $this->_ConvertBytes($int);
  66.            
  67.         }
  68.        
  69.         # Type
  70.         public function _Type($array){
  71.            
  72.             if(!is_array($array)){
  73.                
  74.                 $array = explode('|',$array);
  75.                
  76.             }
  77.            
  78.             $this->_Type = $array;
  79.            
  80.         }
  81.        
  82.         # Extencion
  83.         private function _Extencion(){
  84.            
  85.             $var = explode('.',$_FILES[$this->_Name]['name']);
  86.             $this->_Extencion = strtolower(end($var));
  87.  
  88.         }
  89.        
  90.         # Validador
  91.         private function _Validator(){
  92.            
  93.             # MinSize
  94.             if($this->_MinSize!==NULL && $this->_Name['size'] < $this->_MinSize){
  95.                
  96.                 echo 'El archivo es inferior a los $this->_MinSize bytes';
  97.                 return false;
  98.                
  99.             }
  100.            
  101.             # MaxSize
  102.             if($this->_MaxSize!==NULL && $this->_Name['size'] > $this->_MaxSize){
  103.                
  104.                 echo 'El archivo es mayor a los $this->_MinSize bytes';
  105.                 return false;
  106.                
  107.             }
  108.            
  109.             # Extencion
  110.             if($this->_Extencion!==NULL && !in_array($this->_Extencion,$this->_Type)){
  111.            
  112.                 echo 'El archivo no es valido.';
  113.                 return false;
  114.            
  115.             }
  116.            
  117.             # Escribir Carpeta
  118.             if($this->_Path!==NULL && !is_writable($this->_Path)){
  119.                
  120.                 echo 'Lo sentimos pero no tienes permisos para escribir en $this->_Path';
  121.                 return false;
  122.             }
  123.            
  124.             return true;
  125.         }
  126.        
  127.         # UploadSave
  128.         public function _UploadSave($name){
  129.            
  130.             $this->_Extencion();
  131.            
  132.             if($this->_Validator()){
  133.            
  134.                 return move_uploaded_file($_FILES[$this->_Name]['tmp_name'],$this->_Path.'/'.$name.'.'.$this->_Extencion);
  135.            
  136.             }
  137.            
  138.         }
  139.        
  140.     }

La forma de uso que le doy:
Código PHP:
Ver original
  1. # Upload
  2.     $Upload         = new Cm_Upload;
  3.     $Upload->UploadConfig('Foto','../../Content/Merchandising');
  4.     $Upload->_Type('jpg,png,gif,bmp');
  5.     $Uploaded = $Upload->_UploadSave('Producto'.$Rand);

El problema radica en la funcion _Validator(); especificamente en esta comprobacion:

Código PHP:
Ver original
  1. # Extencion
  2.             if($this->_Extencion!==NULL && !in_array($this->_Extencion,$this->_Type))


Hice un echo de $this->_Extencion y me retorna la extencion perfectamente.
Hice un echo de $this->_Type y me retorna un array, recorri ese array y esta perfecto, busque sobre el tema por sangoogle, pero no encontre nada, lo probe y lo probe pero siempre me retorna false :S cuando deberia retornar un true, alguien me podria ayudar? seria de mucha utilidad :)