Ver Mensaje Individual
  #9 (permalink)  
Antiguo 25/08/2006, 11:47
Avatar de Belero
Belero
 
Fecha de Ingreso: agosto-2006
Mensajes: 98
Antigüedad: 17 años, 8 meses
Puntos: 0
Veamos con un ejemplo.

subir.php
Supongamos que tienes datos del registro en un array, $registros.
Recorremos el array y generamos las tablas para mostrar los datos de cada registro.
En cada tabla ponemos un formulario para subir un archivo relacionado con ese registro, para ello ponemos un campo hidden con la id del registro y un campo file.

subiendo.php
Comprobamos que se le asigna el archivo a algún registro.
Comprobamos la imagen y la guardamos y asignamos al registro
...

subir.php
Código PHP:
<?php

$registros 
= array(
  
=> array(
    
'id' => '1',
    
'nombre' => 'registro 1',
    
'datos' => 'datosss'
  
),
  
=> array(
    
'id' => '2',
    
'nombre' => 'registro 2',
    
'datos' => 'datosss'
  
)
);


foreach(
$registros AS $registro)
{
  echo 
'
    <table border="1">
      <tr>
        <td>' 
$registro['nombre'] . '</td>
      </tr>
      <tr>
        <td>' 
$registro['datos'] . '</td>
      </tr>
      <tr>
        <td>
          <form action="./subiendo.php" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="' 
$registro['id'] . '" />
            <input type="file" name="archivo" />
            <input type="submit" value="Subir imagen" />
          </form>
        </td>
      </tr>
    </table>
    <br />
  '
;
}

?>
subiendo.php
Código PHP:
<?php

if(!empty($_POST['id']))
{
  
$id intval($_POST['id']);
  
$archivo =& $_FILES['archivo'];
  
  echo 
"Subiendo imagen al registro " $id "<br />";
  
print_r($archivo);
  exit;
  
  
/*
  * Compruebas si existe el registro en la BD
  */
  
  /*
  * Compruebas imagen y la guardamos asociándola al registro
  */
  
  /*
  * . . . . .
  */
}
else
{
  die(
"Fallo al validar el registro.");
}

?>