
Originally Posted by
Kravvitz
Well, mjunior, we can't help you if you don't show us your code.
Here it goes:
HTML Code:
<script type="text/javascript">
// width to resize large images to
var maxWidth=100;
// height to resize large images to
var maxHeight=100;
// valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
// the id of the preview image tag
var outImage="previewField";
// what to display when the image is not valid
var defaultPic="imagens/unavailable.jpg";
function preview(what){
var source=what.value;
var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
globalPic=new Image();
if (i<fileTypes.length) globalPic.src=source;
else {
globalPic.src=defaultPic;
alert("This is not a valid extension for images. Pick one from the supported extensions as :\n\n"+fileTypes.join(", "));
}
setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
var field=document.getElementById(outImage);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
}
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
}
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
field.height=y;
}
</script>
<input type="file" name="File1" id="picField" onChange="preview(this)" size="10" >
<div align="center" style="line-height: 1.9em;">
<img src="imagens/unavailable.jpg" alt="Preview from image" name="previewField" width="100" height="99" border="0" id="previewField"></div>
Bookmarks