jueves, 7 de octubre de 2010

codigo subir imagen

<html>
<head>
<title>insertar personal</title>

</head>
<body bgcolor=#008080>

<FORM ACTION="insertarpersona.php" METHOD="post" ENCTYPE="multipart/form-data">
<input type = "file" name="imagen"><br>
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE='560800'>
 <INPUT TYPE="submit" name="enviar" VALUE="Insertar">
</FORM>
<?php //para subir la imagen
if ($enviar == "Insertar")
    echo "se presiono el boton";
if (is_uploaded_file ($_FILES['imagen']['tmp_name']))
{
    $nombreDirectorio = "img/";
       $nombreFichero = $_FILES['imagen']['name'];

    $nombreCompleto = $nombreDirectorio . $nombreFichero;
       if (is_file($nombreCompleto))
       {
              $idUnico = time();
              $nombreFichero = $idUnico . "-" . $nombreFichero;
       }

       move_uploaded_file ($_FILES['imagen']['tmp_name'],
          $nombreDirectorio . $nombreFichero);
    $imagensubida=$nombreFichero;
    //print ($imagensubida);
}
else
       print ("No se ha podido subir el fichero\n");
//fin de subir la imagen
?>
 <br>
<?php
    mysql_connect("localhost","root","123456");
    $sentencia="insert into tpersonal(img_p) values ('".$imagensubida."')";
    mysql_db_query("luna",$sentencia);
    echo "<h1>".$sentencia."</h1><br>";
?>   

<?php //tabla para mostrar
mysql_connect("localhost","root","123456");
//Ejecutamos la sentencia SQL
$sentencia = "SELECT * FROM Tpersonal ";
$result=mysql_db_query("luna",$sentencia);


?>
<CENTER><h2>PERSONAL LUNA LUNAR</H2></CENTER>
<table width="100%" align="center" border="1">
  <tr>
<th width ="20%" align="center" bgcolor=#FFFFCC>Imagen</th>
<?php
while ($row=mysql_fetch_array($result))
{
echo "<tr><td align='center' bgcolor=#CCCCCC><img border=1 src='img/".$row['img_p']."' width = 80 heigth = 80></td>";

}
mysql_free_result($result);
?>
</tr>
</table>

</body>
</html>

No hay comentarios:

Publicar un comentario