![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
08/02/2008, 10:42
|
| | Fecha de Ingreso: junio-2006
Mensajes: 126
Antigüedad: 18 años, 7 meses Puntos: 0 | |
Re: Como hacer que el boton input file sea submit? hola caricatos mira segun tu ejemplo yo tengo 3 archivos check_form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Formulario</title>
<script type="text/javascript">
function actuar(peso, anchura, altura) {
this.peso.value = peso;
this.ancho.value = anchura;
this.alto.value = altura;
}
function ini() {
document.forms.formu.actualizar = actuar;
window.frames.ver.location.href = "previsor.php";
document.forms.formu.actualizar(0, 0, 0);
}
function validar(f) {
enviar = /\.(gif|jpg|png)$/i.test(f.archivo.value);
if (!enviar) alert("seleccione imagen");
return enviar;
}
function limpiar() {
document.forms.formu.actualizar(0, 0, 0);
f = document.getElementById("archivo");
nuevoFile = document.createElement("input");
nuevoFile.id = f.id;
nuevoFile.type = "file";
nuevoFile.name = "archivo";
nuevoFile.value = "";
nuevoFile.onchange = f.onchange;
nodoPadre = f.parentNode;
nodoSiguiente = f.nextSibling;
nodoPadre.removeChild(f);
(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
}
function checkear(f) {
function no_prever() {
alert("El fichero seleccionado no es válido...");
limpiar();
}
function prever() {
var campos = new Array("maxpeso", "maxalto", "maxancho");
for (i = 0, total = campos.length; i < total; i ++)
f.form[campos[i]].disabled = false;
actionActual = f.form.action;
targetActual = f.form.target;
f.form.action = "previsor.php";
f.form.target = "ver";
f.form.submit();
for (i = 0, total = campos.length; i < total; i ++)
f.form[campos[i]].disabled = true;
f.form.action = actionActual;
f.form.target = targetActual;
}
(/\.(gif|jpg|png)$/i.test(f.value)) ? prever() : no_prever();
}
function datosImagen(peso, ancho, alto, error) {
function mostrar_error() {
enviar = false;
mensaje = "Ha habido un error (error nº " + error + "):";
if (error % 2 == 1) // tipo incorrecto
mensaje += "\nel fichero no es válido";
error = parseInt(error / 2);
if (error % 2 == 1) // excede en peso
mensaje += "\nla imagen pesa mogollón (" + peso + ").";
error = parseInt(error / 2);
if (error % 2 == 1) // excede en anchura
mensaje += "\nla imagen excede en anchura (" + ancho + ").";
error = parseInt(error / 2);
if (error % 2 == 1) // excede en altura
mensaje += "\nla imagen excede en altura (" + alto + ").";
error = parseInt(error / 2);
alert (mensaje);
limpiar();
}
if (error == 0)
document.forms.formu.actualizar(peso, ancho, alto);
else
mostrar_error();
}
</script>
<style type="text/css">
html {
margin: 0;
}
body {
margin: auto;
background-color: #abcabc;
}
h1 {
text-align: center;
background: #eeeeee url(../dibujos/miemoticon.gif) no-repeat 1% 50%;
color: blue;
margin: 0;
height: 50px;
}
p {
margin: 0;
text-align: justify;
text-indent: 1cm;
}
#intro {
margin: .5cm;
padding: .5cm;
background-color: #defdef;
color: black;
}
</style></head><body onLoad="ini()">
<h1>
Formulario (chequeo de imágenes)
</h1>
<div id="intro">
<p>
En este formulario se puede elegir una imagen del tipo gif/png/jpg, y se mostrará
en un recuadro reservado para la previsualización. Si la extensión no fuera la deseada
se limpiará el campo y no podrá enviarse hasta que la imagen sea de la extensión correcta.
</p>
<p>
Existen también tres campos deshabilitados con las medidas permitidas para esa imagenes
(maxpeso, maxancho y maxalto)
</p>
</div>
<form target="" action="receptor.php" method="post" enctype="multipart/form-data" onSubmit="return validar(this)"
name="formu" style="margin: auto; text-align: center;">
<input name="archivo" id="archivo" type="file" onChange="checkear(this)">
<fieldset style="width: 80%;"><legend>Límites aceptados</legend>
peso máximo:
<input disabled="disabled" name="maxpeso" value="80000" type="text">
anchura máxima:
<input disabled="disabled" name="maxancho" value="640" type="text">
altura máxima:
<input disabled="disabled" name="maxalto" value="480" type="text">
</fieldset>
<fieldset style="width: 80%;"><legend>Valores actuales</legend>
peso actual:
<input readonly="readonly" name="peso" value="0" type="text">
anchura actual:
<input readonly="readonly" name="ancho" value="0" type="text">
altura actual:
<input readonly="readonly" name="alto" value="0" type="text">
</fieldset>
<textarea name="mensaje" style="width: 80%; height: 100px;">comentarios</textarea>
<br>
<button type="submit" id="bb" style="text-align: center;">enviar formulario (pruebas)</button>
</form>
<iframe src="previsor.php" id="ver" name="ver" style="border-width: 2px; margin: auto; display: block; width: 484px; height: 364px;">
</iframe>
<hr>
<p style="text-align: center; color: red; visibility: visible;" id="aviso">
Selecciones una imagen gif/png/jpg
</p>
<br /><div style="z-index:3" class="smallfont" align="center"><!-- google_ad_section_start(weight=ignore) -->LinkBacks Enabled by <a rel="nofollow" href="http://www.crawlability.com/vbseo/">vBSEO</a> 3.1.0<!-- google_ad_section_end --></div></body></html> receptor.php
<?php
session_start();
$defecto = "webmaster.gif";
$Ok = isset($_FILES["archivo"]);
$url = ($Ok) ? $_FILES["archivo"]["tmp_name"] : $defecto;
list($anchura, $altura, $tipoImagen, $atributos) = getimagesize($url);
$error = (isset($atributos)) ? 0 : 1;
$los_tipos = array("gif", "jpg", "png");
$tipo = ($Ok) ? "image/".$los_tipos[$tipoImagen - 1] : "image/gif";
$fichero = ($Ok && ($error == 0)) ? $_FILES["archivo"]["name"] : $defecto;
$tam = filesize($url);
$OkTam = isset($_POST["maxpeso"]);
$OkAncho = isset($_POST["maxancho"]);
$OkAlto = isset($_POST["maxalto"]);
$maxTam = ($OkTam) ? (int) $_POST["maxpeso"]: 100000;
$maxAncho = ($OkAncho) ? (int) $_POST["maxancho"]: 640;
$maxAlto = ($OkAlto) ? (int) $_POST["maxalto"]: 480;
$error += ($tam <= $maxTam) ? 0 : 2;
$ancho = ($error == 1) ? 0 : $anchura;
$alto = ($error == 1) ? 0 : $altura;
$error += ($ancho <= $maxAncho) ? 0 : 4;
$error += ($alto <= $maxAlto) ? 0 : 8;
$datos = ($error == 0) ? $url : $defecto;
$onload = ($Ok) ? "onload='parent.datosImagen($tam, $ancho, $alto, $error)'": '';
$datos_imagen = fread(fopen($datos, "rb"), filesize($datos));
$_SESSION["cont"] = $datos_imagen;
$_SESSION["tipo"] = ($error == 0) ? $tipo : "image/gif";
?>
<html>
<head>
<style type="text/css" >
html {
margin: 0;
height: 100%;
}
body {
height: 100%;
background-image: url(previendo.php?dato=<?=$fichero;?>);
background-repeat: no-repeat;
background-position: center center;
}
</style>
</head>
<body <?=$onload;?>>
</body>
</html> previsor.php
<?php
session_start();
$url = ($_SESSION["cont"] == "")
? fread(fopen("webmaster.gif", "rb"), filesize("webmaster.gif"))
: $_SESSION["cont"];
$tip = ($_SESSION["tipo"] == "")
? "image/gif"
: $_SESSION["tipo"];
header("Content-type: $tip");
echo $url;
session_destroy();
?> |