Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/07/2006, 10:39
Avatar de seik!
seik!
 
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 17 años, 10 meses
Puntos: 6
tercera parte y final...

este es el codigo donde inserto a la base datos y subo el registro.
Código PHP:
<link href="../config.inc.css" rel="stylesheet" type="text/css">


<?php 
        
// Paso 1: Recibimos el formulario: 
        
$num_oficio=$_POST["num_oficio"];

        
// Obviamente conectamos 
        
mysql_connect("localhost","root"); 
        
mysql_select_db("bd"); 

        
// Paso 2: Hacemos la consulta a la Tabla por el documento
        
$busquedamysql_query("SELECT num_oficio FROM oficio WHERE num_oficio='".$num_oficio."'"); 


        
// Paso 3: vemos si hubo coincidencias 
        
if(mysql_num_rows($busqueda)>0) { // ó " !=0 " como se quiera ver 
       // Inciso a:  
                  
echo "<center>
                <table> 
                        <tr>
                            <td height='100' width='30' class='ti_12_negro' ></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center' class='ti_14_azul' bgcolor='#CCFFFF'>Número de documneto ya existe dentro de los registros, favor ingrese nuevamente</td>
                        </tr>
                        <tr>
                            <td height='30'></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center'><input type='button' class='button' name='cmdsalir' value='Regresar' onclick='javascript:history.back()'></td>
                        </tr>
                </table>"
;           
                } else {
?>
   
<?php
        
// Configuración //
        ///////////////////
        // $extensiones=array("1ªext","2ªext","....");
        // Aqui debes poner las extensiones que NO admitas
        // por ejemplo si no quieres admitir .html , .exe ni .gif :
        // $extensiones=array("html","exe","gif");
        ///////////////////////////////////////
        
$extensiones=array("");
        
/////////////////
        // $path="/ruta/ta/ta";
        // Si el server rula bajo LinuX toda la ruta completa /var/etc/..
        // Si rulas bajo WindoWs C:/midirectorioroot/tal..
        // Nota: Sin el último / ej: C:/miweb NO C:/miweb/
        ////////////////
        
$path="C:/Inetpub\wwwroot\sec2\oficios";
        
$nombre=$_FILES['archivo']['name'];
        
$tamanio=$_FILES['archivo']['size'];
        
$tipo=$_FILES['archivo']['type'];
        
$var explode(".","$nombre");
        
$num count($extensiones);
        
$valor $num-1;
        
            for(
$i=0$i<=$valor$i++) {
                if(
$extensiones[$i] == $var[1]) {
                echo 
"<center><table> 
                    <tr>
                        <td height='100' width='30' class='ti_12_negro' ></td>
                    </tr>
                    <tr>
                        <td height='40' width='330' align='center' class='ti_12_negro' bgcolor='#CCFFFF'>Archivo no admitido</td>
                    </tr>
                    <tr>
                        <td height='30'></td>
                    </tr>
                    <tr>
                        <td height='40' width='330' align='center'><input type='button' class='button' name='cmdsalir' value='Salir' onclick='javascript:window.close();'></td>
                    </tr>
                    </table>"
;
                    
$verifica=1;
                    exit;
                }
            }
        
        
$nombre_archivo $_POST["num_oficio"].substr($nombrestrlen($nombre) - 44);
        
            if (
is_uploaded_file($_FILES['archivo']['tmp_name']))
                 {
                  
move_uploaded_file($_FILES['archivo']['tmp_name'], "$path/$nombre_archivo");
                  echo 
"<center>
                    <table> 
                        <tr>
                            <td height='100' width='30' class='ti_12_negro' ></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center' class='ti_12_negro' bgcolor='#CCFFFF'>Datos ingresados correctamente!
                            </td>
                        </tr>
                        <tr>
                            <td height='30'></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center'></td>
                        </tr>
                    </table>"
;
                     
                }
            else
                     { 
                 echo 
"<center>
                    <table> 
                        <tr>
                            <td height='100' width='30' class='ti_12_negro' ></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center' class='ti_12_negro' bgcolor='#CCFFFF'>Error al subir el archivo</td>
                        </tr>
                        <tr>
                            <td height='20'></td>
                        </tr>
                        </table>"
;
                        
$verifica=1;
                    }
?>

      
    <CENTER>
         <input type="button"  name="cmdaceptar" value="Aceptar" class="button" onclick="javascript:window.close();">
    </CENTER>
 <br> 
<?php if ($verifica==0){ ?>
<?php
                $nom_oficio
=$_POST["nom_oficio"];
                
$ant_oficio=$_POST["ant_oficio"];
                
$mat_oficio=$_POST["mat_oficio"];
                
$fecha_oficio=$_POST["fecha_oficio"];
                
$fecha_recepcion_oficio=$_POST["fecha_recepcion_oficio"];
                
$estado_oficio =$_POST["selestado_oficio"];
                
$tipo_oficio=$_POST["seltipo_oficio"];
                
$organismo=$_POST["selorganismo"];
                    
                
$link mysql_connect("localhost""root") or die("Could not connect to database!");
                
mysql_select_db("bd") or die("Could not select database!");
                
                
$query "INSERT INTO oficio (nom_oficio, num_oficio, ant_oficio";
                
$query.= ", mat_oficio, fecha_oficio, fecha_recepcion_oficio, archivo, estado_oficio, tipo_oficio, organismo) VALUES ";
                
$query.= "('".$nom_oficio."',".$num_oficio.",'".$ant_oficio."','".$mat_oficio."'";
                
$query.= ", '".$fecha_oficio."','".$fecha_recepcion_oficio."','".$nombre_archivo."','".$estado_oficio."','".$tipo_oficio."','".$organismo."')";
                
$result mysql_query($query$link);
?>
    
<?php //agregamos registron en los detalles
        
$num_oficio_evento=$num_oficio;
        
$evento_tipo "Ingreso datos";    
        
$evento_fecha $gfecha_hora_sistema;
        
$evento_user $_POST["evento_user"];
        
$query "INSERT INTO evento (num_oficio_evento, evento_tipo, evento_fecha, evento_user) VALUES";
        
$query.= "(".$num_oficio_evento.",'".$evento_tipo."','".$evento_fecha."','".$evento_user."')";
            
        
$result2 mysql_query($query$link);
    
?>
<script languaje="javascript">    
        top.opener.document.location = top.opener.document.location;
</script>
<?php } } ?>
si se dan cuenta logre validar pero al direccionar al otro php igual carga el archivo... y pierdo mucho tiempo si este es pesado.

saludos espero me ayuden
__________________
sEIK! -Chile-
Analista Programador.

Última edición por seik!; 18/07/2006 a las 10:56