-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatepic2.jsp
74 lines (66 loc) · 2.36 KB
/
updatepic2.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Registration Form</title>
<link rel="stylesheet" href="css/style.css">
</head>
<%@ page import="com.mysql.*" %>
<%@ page import="java.io.*,java.sql.*"%>
<%
///
String email=(String)session.getAttribute("email");
String saveFile="";
//String contentType=request.getAttribute("file");
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;
File ff = new File("D://"+saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
File f=new File("D://"+saveFile);
FileInputStream fis=new FileInputStream("D://"+saveFile);
//
// System.out.println(ff.getName());
// open input stream test.txt for reading purpose.
String pname=ff.getName().toString();
//session.setAttribute("pname",pname);
try{
Connection con = DatabaseCon.getConnection();
//b1=new Blob(b);
PreparedStatement pst=con.prepareStatement("update profilepic set pic=? where email='"+email+"' ");
pst.setBinaryStream(1,(InputStream)fis,(int)(f.length()));
int i=pst.executeUpdate();
if(i==1)
{
out.println("update");
response.sendRedirect("u_home.jsp?id=suc ");
}
}catch(Exception e){
e.printStackTrace();
}
}
%>