Foros del Web » Programando para Internet » PHP »

Como añadir la opcion de subir imagen con un formulario ya hecho

Estas en el tema de Como añadir la opcion de subir imagen con un formulario ya hecho en el foro de PHP en Foros del Web. Hola de nuevo compañeros le agradezco su atencion en este tema...estoy en busqueda de un script o un ejemplo claro que me ayude a subir ...
  #1 (permalink)  
Antiguo 08/09/2008, 19:06
 
Fecha de Ingreso: junio-2008
Ubicación: Maracay
Mensajes: 52
Antigüedad: 15 años, 10 meses
Puntos: 0
Como añadir la opcion de subir imagen con un formulario ya hecho

Hola de nuevo compañeros le agradezco su atencion en este tema...estoy en busqueda de un script o un ejemplo claro que me ayude a subir una imagen de una unidad vehicular, el formulario que ya tengo hecho necesitaria agregarle la opcion de subir la imagen, la imagen se deberia guardarse en una carpeta del sistema con su direccion que la almacena en un BD de MySQL...o solo almacenaria dentro de la misma BD como blob o longblob, ya he recopilado informacion y solo consigo subir imagen con formularios muy diferentes y hasta se conigue uno con clase y no consigo adaptarlo a mi formulario,..pero consegui algo parecido que me podria ayudar pero estoy mas enredado que pelo en pata de pollo jejeje...

Este es el formulario
Código PHP:
<?
  
// Rescatar Variables del Formulario
  
$txtCI$_POST['txtCI'];
  
$txtNombre$_POST['txtNombre'];
  
$txtApellidos$_POST['txtApellidos'];
  
$optSexo$_POST['optSexo'];
  
$cobDia=$_POST['cobDia'];
  
$cobMes=$_POST['cobMes'];
  
$txtA&#241;o=$_POST['txtAño'];
  
$cobDiaingre=$_POST['cobDiaingre'];
  
$cobMesingre=$_POST['cobMesingre'];
  
$txtA&#241;oingre=$_POST['txtAñoingre'];
  
$txtDireccion=$_POST['txtDireccion'];
  
$txtTelefono=$_POST['txtTelefono'];
  
$dbcDepartamento=$_POST['dbcDepartamento'];
  
$txtClave=$_POST['txtClave'];
  
$txtConfirmarclave=$_POST['txtConfirmarclave'];
  
$btnAccion=$_POST['btnAccion'];
  
//Determinar La Accion
  
if($btnAccion=='Buscar'){
    echo 
"Se quiere Buscar...$btnAccion";
    
// 1.Conectar con MSQL
    
$Conectar=mysql_connect("localhost","root","");
    
// 2.Asignar Variable de B.D
    
$bd="personal";
    
// 3.Asignar Variable de SQL
    
$SQL="SELECT * FROM empleados WHERE ci='$txtCI'";
    
// 4.Ejecutar consulta
    
$resultado=mysql_db_query($bd,$SQL);
    
// 5.Mostrar Error
    
echo "error:".mysql_error();
    
// 6.Lo encontro?
    
$NRORegistro=mysql_num_rows($resultado);
    
//echo "num: $SQL";
    
if ($NRORegistro==0){

    
?>
    <script>
    alert('NO SE ENCUENTRA REGISTRADO');
    </script>
    <?
     $btnAccion
='Limpiar';
    }else{
      
$Registro=mysql_fetch_array($resultado);
      
$txtCI=$Registro[0];
      
$txtNombre$Registro[1];
      
$txtApellidos$Registro[2];
      
$optSexo$Registro[3];
     
$txtA&#241;o= $Registro[4]
      
$txtDireccion$Registro[5];
      
$txtTelefono$Registro[6];
      
$dbcDepartamento$Registro[7];
      
$txtClave$Registro[8];
      
$txtConfirmarclave$Registro[8];
    }

    }else if(
$btnAccion=='Agregar'){
  echo 
"Se quiere Agregar...";
   
// 1.Conectar con MSQL
   
$Conectar=mysql_connect("localhost","root","");
   
// 2.Asignar Variable de B.D
  
$bd="personal";
   
// 3.Asignar Variable de SQL

     
$Codificar=md5($txtClave);
   
$SQL="INSERT INTO `personal`.`empleados` (`ci` ,
                                             `nombres` ,
                                             `apellidos` ,
                                             `sexo` ,
                                             `anio` ,
                                             `direccion` ,
                                              `telefono` ,
                                               `coddepartamento` ,
                                               `clave` )
                                      VALUES ('$txtCI',
                                              '$txtNombre',
                                              '$txtApellidos',
                                              '$optSexo',
                                              '$txtAño',
                                              '$txtDireccion',
                                              '$txtTelefono',
                                              '$dbcDepartamento',
                                              '$Codificar');"
;
 
// 4.Ejecutar SQL
 
$resultado=mysql_db_query($bd,$SQL);
 
// 5.Mostrar Error
 
echo "error:".mysql_error();


  }else if(
$btnAccion=='Modificar'){
  echo 
"Se quiere Modificar...";
  
// 1.Conectar con MSQL
   
$Conectar=mysql_connect("localhost","root","");
   
// 2.Asignar Variable de B.D
  
$bd="personal";
   
// 3.Asignar Variable de SQL

   
$Codificar=md5($txtClave);
     
$SQL="UPDATE `personal`.`empleados` SET   `nombres`='$txtNombre',
                                              `apellidos`='$txtApellidos',
                                              `sexo`='$txtSexo' ,
                                              `anio`='$txtAño',
                                              `direccion`='$txtDireccion',
                                              `telefono`='$txtTelefono',
                                              `coddepartamento`='$dbcDepartamento',
                                              `clave`='$Codificar'
                                               WHERE ci='$txtCI'"
;

 
// 4.Ejecutar SQL
 
$resultado=mysql_db_query($bd,$SQL);
 
// 5.Mostrar Error
 
echo "error:".mysql_error();
  }
  else if(
$btnAccion=='Eliminar'){
  echo 
"Se quiere Eliminar...";
  
// 1.Conectar con MSQL
    
$Conectar=mysql_connect("localhost","root","");
    
// 2.Asignar Variable de B.D
    
$bd="personal";
    
// 3.Asignar Variable de SQL
    
$SQL="DELETE FROM empleados WHERE ci='$txtCI'";
    
// 4.Ejecutar consulta
    
$resultado=mysql_db_query($bd,$SQL);
    
// 5.Mostrar Error
    
echo "error:".mysql_error();
  }
  if(
$btnAccion=='Limpiar'){
  echo 
"Se quiere Limpiar...";
  
$txtCI="";
  
$txtNombre="";
  
$txtApellidos="";
  
$optSexo="F";
  
$txtA&#241;o="AAAA";
  
$txtDireccion="";
  
$txtTelefono="";
  
$dbcDepartamento=0;
  
$txtClave="";
  
$txtConfirmarclave="";

  }


?>

<br /><br />

<form action="<? echo $PHP_SELF?>" name="fdmEmpleados" method="post">
 <fieldset>
 <legend>
 Formulario Registro de Usuario
 </legend>
 <br />
 <label>C.I.:</label>
 <input type="text" name="txtCI" size="12" maxlength="12" value="<?=$txtCI;?>"/><br />
 <label>Nombre.:</label>
 <input type="text" name="txtNombre" size="20" maxlength="20" value="<?=$txtNombre;?>" /><br />
 <label>Apellidos.:</label>
 <input type="text" name="txtApellidos" size="20" maxlength="20" value="<?=$txtApellidos;?>" /><br />
 <label>Sexo.:</label>
 <input type="radio" name="optSexo" value="F" <?=($optSexo=="F"?"checked":"");?> /> Femenino
 <input type="radio" name="optSexo" value="M" <?=($optSexo=="M"?"checked":"");?>/> Masculino<br />
 <input type="text" name="txtAñoingre" size="4" maxlength="4" value="<?=$txtA&#241;o;?>"/><br />
<label>Direccion.:</label>
 <input type="text" name="txtDireccion" size="20" maxlength="20" value="<?=$txtDireccion;?>"/><br />
 <label>Telefono.:</label>
 <input type="text" name="txtTelefono" size="20" maxlength="20" value="<?=$txtTelefono;?>"/><br />
 <label>Departamento.:</label>
 <select name="dbcDepartamento" size="1">
<option>Seleccione Departamento</option>
<?
   
// 1.Conectar con MSQL
   
$Conectar=mysql_connect("localhost","root","");
   
// 2.Asignar Variable de B.D
    
$bd="personal";
   
// 3.Asignar Variable de SQL
   
$SQL="SELECT * FROM departamentos";
   
// 4.Ejecutar SQL
   
$resultado=mysql_db_query($bd,$SQL);
   while(
$registro=mysql_fetch_array($resultado)){
     if(
$dbcDepartamento==$registro[0])
       
$seleccionado="selected";
     else
       
$seleccionado="";
     echo
"<option value=\"$registro[0]\" $seleccionado>$registro[1]</option>";
   }
?>

</select> <br />

<label>Clave:</label>
 <input type="password" name="txtClave" size="10" maxlength="10" value="<?=$txtClave;?>"/><br />
 <label>Confirmar Clave.:</label>
 <input type="password" name="txtConfirmarClave" size="10" maxlength="10" value="<?=$txtConfirmarclave;?>"/><br /><br />

 </fieldset>
<br />
<input type="submit" name="btnAccion" value="Buscar" />
<input type="submit" name="btnAccion" value="Agregar" />
<input type="submit" name="btnAccion" value="Modificar" />
<input type="submit" name="btnAccion" value="Eliminar" />
<input type="submit" name="btnAccion" value="Limpiar" />

</form>

</body>

</html>
Este es un formulario simple funcionando con $_POST, si quieren usenlo para ustedes es muy sencillo, lo que deseo es que pueda examinar la imagen y que se guarde cuando se le marque el boton agregar junto con los otros elementos del formulario ya listos todos para agregar sin ser independiente y ajustar un tamaño especifico que se puedan ver las imagenes, y acepte los formatos jpg, gif y png.
En teoria esto fue lo que consegui:
en esta pagina http://www.webnova.com.ar/articulo.php?recurso=293
y otras paginas explican bien pero no se ajusta a lo que busco
Si bien es una idea pero yo en realidad soy novato y estoy abriendome caminos con el php y mysql...hermanos estare muy agredecido si me ayudan.

Última edición por DjKelvim; 08/09/2008 a las 19:15
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 05:52.