Foros del Web » Programando para Internet » PHP »

ayuda filtrar archivos al subir

Estas en el tema de ayuda filtrar archivos al subir en el foro de PHP en Foros del Web. hola tengo un archivo en k tengo la funcion para validar el tipo de archivo a subir que es este y es una funcion para ...
  #1 (permalink)  
Antiguo 16/02/2007, 11:16
 
Fecha de Ingreso: abril-2006
Mensajes: 240
Antigüedad: 18 años
Puntos: 1
ayuda filtrar archivos al subir

hola
tengo un archivo en k tengo la funcion para validar el tipo de archivo a subir que es este y es una funcion para filtrar los archivos a subir:
Código PHP:
$registered_types = array(
                    
"application/x-gzip-compressed"     => ".tar.gz, .tgz",
                    
"application/x-zip-compressed"         => ".zip",
                    
"application/x-tar"                    => ".tar",
                    
"text/plain"                        => ".html, .php, .txt, .inc (etc)",
                    
"image/bmp"                         => ".bmp, .ico",
                    
"image/gif"                         => ".gif",
                    
"image/pjpeg"                        => ".jpg, .jpeg",
                    
"image/jpeg"                        => ".jpg, .jpeg",
                    
"application/x-shockwave-flash"     => ".swf",
                    
"application/msword"                => ".doc",
                    
"application/vnd.ms-excel"            => ".xls",
                    
"application/octet-stream"            => ".exe, .fla (etc)",
                    
"audio/mpeg"                     => ".mp3",
                    
"audio/x-ms-wma"                 => ".wma",
                    
"application/x-pn-realaudio"    => ".ram, rm",
                    
"video/mpeg"                    => ".mpeg, mpg, mpe",
                    
"video/x-ms-wmv"                => ".wmv",
                    
"video/quicktime"                => ".mov",
                    
"video/x-msvideo"                => ".avi"
                    
);
$allowed_types = array("image/pjpeg","image/jpeg","image/gif","application/x-zip-compressed","application/x-shockwave-flash","application/msword","application/vnd.ms-excel");


function 
validate_upload($file$file_type$file_size$file_name) {
global 
$max_filesize$allowed_types$registered_types;

    
$start_error "\n<b>Error: </b>\n";

    if(
$file==""){ # Vemos si hay archivos
        
$error .= "\n<li>No se ingresaron archivos.</li>";
    }else{ 
# Ver si los tipos son los correctos
        
if (!in_array($file_type,$allowed_types)) {
            
$error .= "\n El archivo $file_name no pudo subirse. Este sistema solo soporta archivos :\n";
            while(
$type current($allowed_types)) {
                
$error .= "\n<li>" $registered_types[$type] . " (" $type ")</li>";
                
next($allowed_types);
            }
            
$error .= "\n";
        }

        if (
ereg("file",$file_type) && (in_array($file_type,$allowed_types))) {

            if (
$file_size $max_filesize)
                
$error .= "\n<li>Su archivo $file_name no puede tener un tamaño mayor a " $max_filesize/1024 " Kb</li>";

        }

        if (
$error){
            
$error $start_error $error "\n</ul>";
            return 
$error;
        } else {
            return 
false;
        }
    }

la pagina k ejecuta la accion a subir m inserta todos los archivos pero no me esta haciendo el filtrado

Código PHP:
<?php include("../include/config.inc.php");
if(
$boton=="Ingresar"){
    if(
$archivo!=""){
        
$arrArchivo explode("."$archivo_name);
        
$extension $arrArchivo[1];
        
$stdouterror1validate_upload($archivo$archivo_type$archivo_size$archivo_name);
      if(
$stdouterror1){
        
$sql "INSERT INTO noticias (idnoticias, fecha, titulo, resumen, archivo, estado)
                VALUES ('', '$fecha', '$titulo', '$resumen', '$archivo', '$estado')"
;
        
$cursor=execstmt($conn$sql);
        
$idnoticias mysql_insert_id();

       if(
move_uploaded_file($archivo$url."$idnoticias".".$extension")){
            
$sql2 "UPDATE noticias SET archivo='".$idnoticias.".".$extension."' WHERE idnoticias=$idnoticias";
            
execstmt($conn$sql2);
        }else{
            
?>
            <script language="javascript">
                alert("Ha ocurrido un error al tratar de subir el archivo");
                location.href="busca_noticias.php";
            </script>
            <?php
            $sql2 
"DELETE FROM noticias WHERE idnoticias=$idnoticias";
            
execstmt($conn$sql2);

            die();
        }
            
?>
            <script language="javascript">
                alert("La publicacion fue ingresado exitosamente");
                location.href="busca_noticias.php";
            </script>
            <?php
    
}else{
        
?>
            <script language="javascript">
                alert("Ha ocurrido un error ingresar de subir el archivo");
                location.href="busca_noticias.php";
            </script>
        <?php
      
}
  }
}

if(
$boton=="Actualizar"){
    if(
$archivo!=""){
        
$arrArchivo explode("."$archivo_name);
        
$extension1 $arrArchivo[1];
    
$stdouterror1 validate_upload($archivo$archivo_type$archivo_size$archivo_name);
    if(!
$stdouterror){
    if(
move_uploaded_file($archivo$url."$id".".$extension1")){
                
$sql3 "UPDATE noticias SET archivo='".$id.".".$extension1."' WHERE idnoticias=$id";
                
execstmt($conn$sql3);
                }else{
                
?>
                <script language="javascript">
                  alert("Ha ocurrido un error al tratar de subir el archivo");
                  location.href="busca_noticias.php";
                </script>
            <?php

                $sql3 
"DELETE FROM noticias WHERE idnoticias=$id";
                
execstmt($conn$sql3);

                die();
            }
            
?>
            <script language="javascript">
                alert("El archivo fue actualizado exitosamente");
                location.href="busca_noticias.php";
            </script>
        <?php

        
}
    }
}

de antemano muchass gracias
  #2 (permalink)  
Antiguo 16/02/2007, 13:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: ayuda filtrar archivos al subir

No veo de donde obtienes tus variables, pero para validar tu archivo deberias de usar el arreglo $_FILES que crea PHP al subir tu archivo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:44.