Script
Código HTML:
<script type="text/javascript">
<!--//
function GetFileExtension(Filename) {
var I = Filename.lastIndexOf(".");
return (I > -1) ? Filename.substring(I + 1, Filename.length).toLowerCase() : "";
}
function BeforeSubmit(id) {
var Form = document.form1;
var file = Form.file.value;
var Ext = "";
if (file == "") {
alert("No haz seleccionado ninguna imagen");
var tamanos = 1;
}
if (file != "") {
Ext = GetFileExtension(file);
if ((Ext != "jpeg") && (Ext != "jpg") && (Ext != "pjpeg")) {
alert("El archivo no es una imagen válida, debe ser JPG");
var tamanos = 1;
}
}
if (tamanos != 1){
tamano();
}
}
function tamano() {
img = document.createElement("IMG");
img.src = document.getElementById("file").value;
img.id = "fotoFinal";
img.style.display = "none";
document.body.appendChild(img);
setTimeout("alert(Math.round((document.getElementById('fotoFinal').fileSize / 1024)*Math.pow(10,2)) / Math.pow(10,2)); ",500);
}
//-->
</script>
formulario:
Código HTML:
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="file" name="file" id="file" value="" size="32" onchange="BeforeSubmit('File1')" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
no me funciona el script... nose por que?