Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Web
Expertise: Advanced
Feb 5, 2003



Application Security Testing: An Integral Part of DevOps

Allow a Preview of an Image File Selected for Upload

This script gives a preview of an image file selected for upload (even before the upload process takes place). It works in both IE and Netscape. This way, users can see which image is being uploaded, thereby decreasing the chances of wrong files being uploaded.
<input type="file" id="attachfile" onFocus="dolayer();"
onclick="dolayer();" onkeydown="return false;">
<div id="imgdiv" style="border: medium solid steelblue; 
height: 300px; width: 300px; text-align: center; 
vertical-align: middle; font-family:
Verdana; font-size: 10pt; color: navy; 
font-weight: bold;">
<BR><BR><BR>No file uploaded.

<script language="JavaScript">
function dolayer()
	if ( document.getElementById('attachfile').value == '' )
		var img = 
		img.innerHTML = 
<BR><BR>No file uploaded.';
			var filename = 
			var fileextension = 
filename.substring(filename.length - 3);
			if ( fileextension == 
'JPG' || fileextension == 'jpg' || fileextension
== 'GIF' || fileextension == 'gif' || fileextension == 'BMP' ||
fileextension == 'bmp')
				var layerText = 
'<img name=image1
src="file:\/\/\/'+document.getElementById('attachfile').value +'"
width=300 height=300>';
		var img = document.getElementById('imgdiv');
		img.innerHTML = layerText;
		var img = document.getElementById('imgdiv');
		img.innerHTML = "<BR><BR><BR>
<BR><BR><BR>A " + fileextension + " file
has been attached. <BR> 
Preview available only for Image files" ;
Sanjay Nair
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date