Bueno lo he checado y me sale este error
Chrome JavaScript Debugger
Type 'help' for a list of commands.
attached to Sucursal en Linea
uncaught exception TypeError: Cannot set property 'disabled' of undefined
$ next
"Uncaught TypeError: Cannot set property 'disabled' of undefined," source:
http://www.sucursalenlinea.com/Edy/funciones.js (27)
que es esta linea
fichero.form[campos[i]].disabled = false;
paso todos los codes
Prueba.php [donde esta el formu
Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return validar(this)">
<label>
<input type="file" name="archivo" id="archivo" onchange="checkear_extension(this)"/>
</label>
<br />
<iframe src="preview2.php" width="auto" height="auto" id="imagen_pre" frameborder="0"></iframe>
<br />
<label>
<input type="submit" name="button" id="button" value="Enviar" />
</label>
</form>
</body>
</html>
preview.php
Código PHP:
<?php
session_name("Preview");
session_start();
$defecto = "index_38.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(preview2.php?dato=<?=$fichero;?>);
background-repeat: no-repeat;
background-position: center center;
}
</style>
</head>
<body <?=$onload;?>>
</body>
</html>
preview2.php
Código PHP:
<?php
session_name("Preview");
session_start();
$url = ($_SESSION["cont"] == "")
? fread(fopen("index_38.gif", "rb"), filesize("index_38.gif"))
: $_SESSION["cont"];
$tip = ($_SESSION["tipo"] == "")
? "image/gif"
: $_SESSION["tipo"];
header("Content-type: $tip");
echo $url;
session_destroy();
?>
funciones.js
Código javascript
:
Ver originalfunction limpiar() {
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 validar(f) {
enviar = /.(gif|jpg|png)$/i.test(f.archivo.value);
if (!enviar) alert("seleccione imagen");
return enviar;
}
function checkear_extension(fichero) {
function prever() {
var campos = new Array("maxpeso", "maxalto", "maxancho");
for (i = 0, total = campos.length; i < total; i ++)
fichero.form[campos[i]].disabled = false;
actionActual = fichero.form.action;
targetActual = fichero.form.target;
fichero.form.action = "preview2.php";
fichero.form.target = "ver";
fichero.form.submit();
for (i = 0, total = campos.length; i < total; i ++)
fichero.form[campos[i]].disabled = true;
fichero.form.action = actionActual;
fichero.form.target = targetActual;
}
function no_prever() {
alert("El fichero seleccionado no es válido...");
limpiar();
}
(/.(gif|jpg|png)$/i.test(fichero.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);
with (document.forms) {
formu.peso.value = 0;
formu.ancho.value = 0;
formu.alto.value = 0;
}
limpiar();
}
if (error == 0) with (document.forms) {
formu.peso.value = peso;
formu.ancho.value = ancho;
formu.alto.value = alto;
}
else mostrar_error();
}