Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Firefox 3 and input file (See related posts)

The nsIDOMFile interface retrieves data from a file submitted to a form using the input type "file". This allows the file reference to be saved when the form is submitted while the user is using a web application offline, so that the data can be retrieved and uploaded once the Internet connection is restored.

   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   3  	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   4  
   5  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   6  <head>
   7  	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   8  	<title>input type=file & Firefox 3</title>
   9  </head>
  10  
  11  <body>
  12  	
  13  <h1>input type=file & Firefox 3</h1>
  14  	
  15  <script type="text/javascript">
  16  // <![CDATA[
  17  
  18  function inputFileOnChange() {
  19  	var v_console = '';
  20  	v_console += 'value: ' + document.getElementById('my-file').value;
  21  	v_console += '<br \/>';
  22  	
  23  	if(document.getElementById('my-file').files) {
  24  		// Support: nsIDOMFile, nsIDOMFileList
  25  		v_console += 'files.length: ' + document.getElementById('my-file').files.length;
  26  		v_console += '<br \/>';
  27  		
  28  		v_console += 'fileName: ' + document.getElementById('my-file').files.item(0).fileName;
  29  		v_console += '<br \/>';
  30  		
  31  		v_console += 'fileSize: ' + document.getElementById('my-file').files.item(0).fileSize;
  32  		v_console += '<br \/>';
  33  		
  34  		v_console += 'data: ' + document.getElementById('my-file').files.item(0).getAsDataURL();
  35  //		v_console += 'data: ' + document.getElementById('my-file').files.item(0).getAsBinary();
  36  //		v_console += 'data: ' + document.getElementById('my-file').files.item(0).getAsText();
  37  		v_console += '<br \/>';
  38  	};
  39  	
  40  	document.getElementById('console').innerHTML = v_console;
  41  };
  42  
  43  // ]]>
  44  </script>
  45  	
  46  <div>
  47  	<input type="file" name="my-file" id="my-file" onchange="inputFileOnChange();" />
  48  	<br /><br />
  49  	<code id="console">...console...< /code>
  50  </div>
  51  	
  52  </body>
  53  </html>


Source: Firefox 3 and input type=file , upload file

You need to create an account or log in to post comments to this site.


Click here to browse all 5545 code snippets

Related Posts