Advertisement
Guest User

example

a guest
Feb 1st, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Split input</title>
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  7. </head>
  8.  
  9. <body>
  10.     <input type="file" id="file" />
  11.     <input type='button' id='load-file' value='Load'>
  12.     <div id="file-content"></div>
  13. </body>
  14.  
  15. <script>        
  16.     ( function ( $ ) {
  17.         $( '#load-file' ).click( function () {
  18.  
  19.             if ( ! window.FileReader ) {
  20.                 return alert( 'FileReader API is not supported by your browser.' );
  21.             }
  22.  
  23.             var $i = $( '#file' ), input = $i[0];
  24.  
  25.             if ( input.files && input.files[0] ) {
  26.                 file = input.files[0];
  27.                 fr = new FileReader();
  28.  
  29.                 fr.onload = function () {
  30.                     var lines = fr.result.split("\n");
  31.                     for (var i = 0, len = lines.length; i < len; i++) {
  32.                         line = lines[i].split(":");
  33.  
  34.                         $( "#file-content" ).append( "Username: " + line[0] + " and password: " + line[1]);
  35.                     }
  36.                 };
  37.  
  38.                 fr.readAsText( file );
  39.             } else {
  40.                 alert( "File not selected or browser incompatible." )
  41.             }
  42.         } );
  43.     } )( jQuery );
  44. </script>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement