Foros del Web » Programando para Internet » PHP »

Problema al subir archivo

Estas en el tema de Problema al subir archivo en el foro de PHP en Foros del Web. Buenas foro.. Tengo un sistema que debe registrar la información de los empleados en la base de datos. Entre esos datos, debe guardar la foto ...
  #1 (permalink)  
Antiguo 11/06/2009, 15:56
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Problema al subir archivo

Buenas foro..

Tengo un sistema que debe registrar la información de los empleados en la base de datos. Entre esos datos, debe guardar la foto del empleado.

Yo deseo guardar unicamente la ruta de la foto del empleado para llamarla y mostrarla cuando requiera (Después de subir el archivo).

Basandome en las faq's de php Faq´s PHP he visto el código para subir archivos al servidor, pero me presenta un problema, al momento de tener dos forms en la misma pagina. uno correspondiente al formulario y otro para cargar correctamente la foto en el formulario. Cuando pincho upload!, me toma el form del formulario y envía los datos al configurado en el primer form sin subirme la foto.

Como podría implementar esta opción de subida de archivos, aparte del formulario principal?

Espero haberme hecho entender.

Un saludo a todos.
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
  #2 (permalink)  
Antiguo 11/06/2009, 15:58
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Problema al subir archivo

Podrias escribir el codigo para poder indicarte
  #3 (permalink)  
Antiguo 11/06/2009, 16:02
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: Problema al subir archivo

Gracias abilmaelc

Código PHP:
Ver original
  1. <form action="inserpersonal.php" method="post" class="Estilo5" onsubmit="return validar(this)" >
  2.         <table width="775" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
  3.           <tr>
  4.             <td width="166" height="24"><div align="left">Identificaci&oacute;n:
  5.               <input name="identificacion" type="text" id="identificacion" size="10" maxlength="10" />
  6.             </div></td>
  7.             <td width="221"><div align="center">Nombres:
  8.                 <input name="nombres" type="text" id="nombres" size="30" maxlength="25" />
  9.             </div></td>
  10.             <td width="204"><div align="right">Apellidos:
  11.                 <input name="apellidos" type="text" id="apellidos" size="30" maxlength="25" />
  12.             </div></td>
  13.           </tr>
  14.           <tr>
  15.             <td colspan="3"><div align="center"></div>              <div align="center"></div>              <div align="center"></div></td>
  16.           </tr>
  17.         </table>
  18.         <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
  19.           <tr>
  20.             <td width="305"><div align="left">Domicilio:
  21.                 <input name="domicilio" type="text" id="domicilio" size="35" maxlength="60" />
  22.             </div></td>
  23.             <td width="222"><div align="center">Telefono:
  24.                 <input name="telefono" type="text" id="telefono" size="15" maxlength="15" />
  25. </div></td>
  26.             <td width="223"><div align="right">Telefono 2:
  27.                 <input name="telefonopc" type="text" id="telefonopc" size="15" maxlength="15" />
  28.             </div></td>
  29.           </tr>
  30.           <tr>
  31.             <td colspan="3">&nbsp;</td>
  32.           </tr>
  33.         </table>
  34.         <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
  35.           <tr>
  36.             <td width="319"><div align="left">Fecha de Nacimiento <span class="Estilo10">D/M/A:
  37.                   <input type=text align=center name=fnacimiento value='<?echo date("d/m/Y");?>' id='f_date_c' style='width:120px;' readonly><img src='images/calendario.gif' id='f_trigger_c' style='cursor: pointer; border: 1px solid green;' title='Selector de Fechas' onmouseover='this.style.background=red;' onmouseout='this.style.background=''' />
  38.             <script type='text/javascript'>
  39.                              Calendar.setup({
  40.                              inputField     :    'f_date_c',     // id of the input field
  41.                              ifFormat       :    '%d/%m/%Y',      // format of the input field
  42.                              button         :    'f_trigger_c',  // trigger for the calendar (button ID)
  43.                              align          :    'Tl',           // alignment (defaults to Bl)
  44.                              singleClick    :    true
  45.                                            });
  46.             </script>        
  47.             </span></div>
  48.             <div align="center"></div></td>
  49.             <td width="210"><div align="center">Estado Civil:
  50.                 <select name="estado" id="estado">
  51.                   <option>Soltero(a)</option>
  52.                   <option>Casado(a)</option>
  53.                 </select>
  54.             </div></td>
  55.             <td width="221"> <div align="right">N&deg; Hijos:
  56.               <select name="nhijos" id="nhijos">
  57.                 <option>0</option>
  58.                 <option>1</option>
  59.                 <option>2</option>
  60.                 <option>3</option>
  61.                 <option>4</option>
  62.                 <option>5</option>
  63.                 <option>6</option>
  64.               </select>
  65.             </div></td>
  66.           </tr>
  67.           <tr>
  68.             <td colspan="3">&nbsp;</td>
  69.           </tr>
  70.         </table>
  71.         <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
  72.           <tr>
  73.             <td width="244"><div align="left">Fecha de Ingreso <span class="Estilo10">D/M/A</span>:<span class="Estilo10">
  74.               <input type=text align=center name=fingreso value='<?echo date("d/m/Y");?>' id='f_date_c1' style='width:120px;' readonly><img src='images/calendario.gif' id='f_trigger_c1' style='cursor: pointer; border: 1px solid green;' title='Selector de Fechas' onmouseover='this.style.background=red;' onmouseout='this.style.background=''' />
  75.             <script type='text/javascript'>
  76.                              Calendar.setup({
  77.                              inputField     :    'f_date_c1',     // id of the input field
  78.                              ifFormat       :    '%d/%m/%Y',      // format of the input field
  79.                              button         :    'f_trigger_c1',  // trigger for the calendar (button ID)
  80.                              align          :    'Tl',           // alignment (defaults to Bl)
  81.                              singleClick    :    true
  82.                                            });
  83.             </script>  
  84.             </span></div></td>
  85.             <td width="253"><div align="center">Tiempo de Contrato:
  86.                 <select name="tcontrato" id="tcontrato">
  87.                   <option>1 Mes</option>
  88.                   <option>3 Meses</option>
  89.                   <option>6 Meses</option>
  90.                   <option>1 A&ntilde;o</option>
  91.                   <option>T. Indefinido</option>
  92.                   <option>O.P.S</option>
  93.                 </select>
  94. </div></td>
  95.             <td width="278"><div align="right">Fecha de Terminacion <span class="Estilo10">D/M/A</span>:<span class="Estilo10">
  96.               <input type=text align=center name=fretiro value='<?echo date("d/m/Y");?>' id='f_date_c2' style='width:120px;' readonly><img src='images/calendario.gif' id='f_trigger_c2' style='cursor: pointer; border: 1px solid green;' title='Selector de Fechas' onmouseover='this.style.background=red;' onmouseout='this.style.background=''' />
  97.             <script type='text/javascript'>
  98.                              Calendar.setup({
  99.                              inputField     :    'f_date_c2',     // id of the input field
  100.                              ifFormat       :    '%d/%m/%Y',      // format of the input field
  101.                              button         :    'f_trigger_c2',  // trigger for the calendar (button ID)
  102.                              align          :    'Tl',           // alignment (defaults to Bl)
  103.                              singleClick    :    true
  104.                                            });
  105.             </script>  
  106.             </span></div></td>
  107.           </tr>
  108.           <tr>
  109.             <td colspan="3">&nbsp;</td>
  110.           </tr>
  111.         </table>
  112.         <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
  113.           <tr>
  114.             <td><div align="left">EPS:
  115.                 <input name="eps" type="text" id="eps" size="25" maxlength="25" />
  116.             </div></td>
  117.             <td><div align="center">Pension:
  118.                 <input name="pension" type="text" id="pension" size="25" maxlength="25" />
  119.             </div></td>
  120.             <td><div align="right">ARP:
  121.                 <input name="arp" type="text" id="arp" size="25" maxlength="25" />
  122.             </div></td>
  123.           </tr>
  124.           <tr>
  125.             <td colspan="3">&nbsp;</td>
  126.           </tr>
  127.         </table>
  128.         <table width="775" border="0" align="center" cellpadding="0" cellspacing="0">
  129.           <tr>
  130.             <td><div align="center">Cargo:
  131.                 <select name="cargo" id="cargo">
  132.                   <option>Administrador(a)</option>
  133.                   <option>Aseo</option>
  134.                   <option>Contador(a)</option>
  135.                   <option>Mensajero(a)</option>
  136.                   <option>Secretaria</option>
  137.                   <option>Servicios Generales</option>
  138.                   <option>Tesorero(a)</option>
  139.                   <option>Vigilante</option>
  140.                 </select>
  141.             </div></td>
  142.        
  143.           </tr>
  144.           <tr>
  145.             <td height="21">&nbsp;</td>
  146.           </tr>
  147.           <tr>
  148.             <td><div align="center">
  149.                 <input name="Crear Vehiculo" type="submit" id="Crear Vehiculo" value="Crear Empleado"/>
  150.             </div></td>
  151.         <td>
  152.         <?php
  153.         if (isset($_POST['submit'])) {  
  154.              if(is_uploaded_file($_FILES['foto']['tmp_name'])) { // verifica haya sido cargado el archivo
  155.                    if(move_uploaded_file($_FILES['foto']['tmp_name'], $_FILES['foto']['name'])) { // se coloca en su lugar final
  156.                           echo "<b>Upload exitoso!. Datos:</b><br>";
  157.                   echo "Nombre: <i><a href=\"".$_FILES['foto']['name']."\">".$_FILES['foto']['name']."</a></i><br>";
  158.                   echo "Tipo MIME: <i>".$_FILES['foto']['type']."</i><br>";
  159.                     echo "Peso: <i>".$_FILES['foto']['size']." bytes</i><br>";
  160.                         echo "<br><hr><br>";
  161.                     }
  162.             }
  163.  
  164.         // A continuación el formulario
  165.         }
  166.         ?>
  167.  
  168.     <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
  169.         Archivo: <input name="foto" type="file">
  170.         <input name="submit" type="submit" value="Upload!">  
  171.     </form>
  172.         </td>  
  173.           </tr>
  174.           <tr>
  175.             <td>&nbsp;</td>
  176.           </tr>
  177.         </table>
  178.       </form>

Verás, En la primera linea está contenido el form que utilizo para llenar los datos del empleado. La ultima parte, traté de implementarla así, ya que pensé que esto se me presentaba por tener un form dentro de otro form, pero los resultados son los mismos.


Mil gracias.
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
  #4 (permalink)  
Antiguo 12/06/2009, 09:02
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: Problema al subir archivo

Aún no logro me funcione.

Alguna idea?
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
  #5 (permalink)  
Antiguo 07/07/2009, 12:53
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: Problema al subir archivo

He dado solución a mi problema con este tutorial
http://php.about.com/od/phpwithmysql...d_file_sql.htm
Cortesía de Jurena

Tuve problemas en la interpretación de la solución propuesta en las faq´s pero en este tutorial que comparto es mucho mas explicita la solución.

Un saludo.
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
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 12:50.