Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <%@ page import="java.util.*" %>
  2. <%@ page import="org.apache.commons.fileupload.*" %>
  3. <%@ page import="org.apache.commons.fileupload.disk.*" %>
  4. <%@ page import="org.apache.commons.fileupload.servlet.*" %>
  5. <%@ page import="org.apache.commons.io.*" %>
  6. <%@ page import="java.io.*" %>
  7.  
  8.  
  9. <%
  10.     String destination = "/files";
  11.     String destinationRealPath = application.getRealPath( destination );
  12.    
  13.     DiskFileItemFactory factory = new DiskFileItemFactory();
  14.     factory.setSizeThreshold( 1024 );
  15.    
  16.     factory.setRepository( new File( destinationRealPath ) );
  17.    
  18.     ServletFileUpload uploader = new ServletFileUpload( factory );
  19.    
  20.     try
  21.     {
  22.         List items = uploader.parseRequest( request );
  23.         Iterator iterator = items.iterator();
  24.        
  25.         while( iterator.hasNext() )
  26.         {
  27.             FileItem item = (FileItem) iterator.next();
  28.             File file = new File( destinationRealPath, item.getName() );
  29.             item.write( file );
  30.             out.write( "<p>" + file.getName() + " was uploaded successfully</p>" ) ;
  31.         }
  32.     }
  33.     catch( FileUploadException e )
  34.     {
  35.         out.write( "<p>FileUploadException was thrown..." + e.getMessage() + "</p>" );
  36.     }
  37.    
  38. %>
  39.