Ver Mensaje Individual
  #7 (permalink)  
Antiguo 27/09/2011, 07:25
Avatar de Eleazan
Eleazan
 
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: (Consulta) Propiedad tipo array y recorrerlo

Bueno, yo he probado esto:
Código PHP:
class Test {
    private 
$allows = array('jpg','png','gif');
    
    
    
    private function 
extension($file) {
       
        return 
substr(strrchr($file'.'), 1);
       
        
    }
    
    public function 
comprobar($file) {
           
$extension_a_comprobar $this->extension($file); //Pq voy a buscar la extension 300 veces? ;)
            
$result false;
            foreach (
$this->allows as $allow) {
               
                if (
$allow == $extension_a_comprobar) {
                    
//Sí q está permitida
                    
$result true;
                }      
            }
                return 
$result;
        }
}

$test = new Test;
if(
$test->comprobar('test.jpg')) echo 'test.jpg aceptado';
if(
$test->comprobar('test.jpeg')) echo 'test.jpeg aceptado'
Y me funciona bien así ;)
__________________
>> Eleazan's Source
>> @Eleazan