
24/01/2011, 08:13
|
| | Fecha de Ingreso: enero-2011
Mensajes: 23
Antigüedad: 14 años, 1 mes Puntos: 0 | |
Respuesta: Problema al Visualizar imagen en formulario Hola! Gracias por contestar.
Si, me parece una buena opción. Mira te mando el código para que te hagas una idea:
<?Php
define ("MAX_SIZE", "100");
function getExtension($str){
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo '<h1>desconocido extensión!</h1>';
$errors=1;
}else{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
echo '<h1>Usted ha excedido el límite de tamaño!</h1>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
}
}
}
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>File Uploaded Successfully! Try again!</h1>";
//aqui accederíamos a guardar en la BBDD
}
?>
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form> La cuestión sería que cuando pulsara el botón "Upload image" se previsualizara la imagen.. |