<%@ page import="java.io.*,java.sql.*,java.util.zip.*,java.util.Date" %>
<%

            String realpath1 = getServletContext().getRealPath("/");
            realpath1 = realpath1.replace('\\', '/');

            String temprealpath = realpath1;
            realpath1 += "backup/";
            out.print(realpath1);
            String saveFile = "";
            String contentType = request.getContentType();
            if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
                DataInputStream in = new DataInputStream(request.getInputStream());
                int formDataLength = request.getContentLength();
                byte dataBytes[] = new byte[formDataLength];
                int byteRead = 0;
                int totalBytesRead = 0;
                while (totalBytesRead < formDataLength) {
                    byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
                    totalBytesRead += byteRead;
                }

                String file = new String(dataBytes);
                saveFile = file.substring(file.indexOf("filename=\"") + 10);
                saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
                saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
                int lastIndex = contentType.lastIndexOf("=");
                String boundary = contentType.substring(lastIndex + 1, contentType.length());
                int pos;
                pos = file.indexOf("filename=\"");
                pos = file.indexOf("\n", pos) + 1;
                pos = file.indexOf("\n", pos) + 1;
                pos = file.indexOf("\n", pos) + 1;
                int boundaryLocation = file.indexOf(boundary, pos) - 4;
                int startPos = ((file.substring(0, pos)).getBytes()).length;
                int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

                java.util.Date today = java.util.Calendar.getInstance().getTime();
                java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
                String folderName = formatter.format(today);

                out.println(folderName);

                String strDirectoy = realpath1 + folderName;

                File ff1 = new File(strDirectoy + saveFile);
                String filename1 = strDirectoy + saveFile;

                FileOutputStream fileOut1 = new FileOutputStream(filename1);
                fileOut1.write(dataBytes, startPos, (endPos - startPos));
                fileOut1.flush();
                fileOut1.close();
%><br><table border="2"><tr><td><b>You have successfully upload the file:</b>
            <%out.println(saveFile);

            %></td></tr>

    <tr><td><a href="Read?filename=<%= filename1%>&temprealpath=<%= temprealpath%>&savefile=<%= saveFile%>">Add to Database</a></td></tr></table>

<%}%>

<!--backup file code-->



