本文整理汇总了Java中com.jspsmart.upload.Files类的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Files类属于com.jspsmart.upload包,在下文中一共展示了Files类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: user_uploadPhoto
import com.jspsmart.upload.Files; //导入依赖的package包/类
public void user_uploadPhoto(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
data = new OperationData();
com.jspsmart.upload.SmartUpload su = new com.jspsmart.upload.SmartUpload();
String information = "��������������������Ƭʧ�ܣ�";
try {
su.initialize(this.getServletConfig(), request, response); // ���ó��������ij�ʼ��
su.setMaxFileSize(2 * 1024 * 1024); // �����ϴ��ļ��Ĵ�С
su.upload();
Files files = su.getFiles(); // ��ȡ�ϴ����ļ�����
for (int i = 0; i < files.getCount(); i++) {
File singleFile = files.getFile(i); // ��ȡ�ϴ��ļ��ĵ����ļ�
String fileType = singleFile.getFileExt(); // ��ȡ�ϴ��ļ�����չ��
String[] type = { "JPG", "jpg", "gif", "bmp", "BMP" }; // �����ϴ��ļ�����չ��
int place = java.util.Arrays.binarySearch(type, fileType); // �ж��ϴ��ļ��������Ƿ���ȷ
String code = su.getRequest().getParameter("code"); // ��ȡ������֤������
String codeSession = (String) request.getSession()
.getAttribute("rand"); // ��ȡ�ͻ���session����֤���ֵ
if (code.equals(codeSession)) { // �ж���֤���Ƿ���ȷ
if (place != -1) { // �ж��ļ���չ���Ƿ���ȷ
if (!singleFile.isMissing()) { // �жϸ��ļ��Ƿ�ѡ��
String photoName = su.getRequest().getParameter(
"photoName")
+ i; // ��ȡ��Ƭ������
String photoType = su.getRequest().getParameter(
"photoType"); // ��ȡ�������
String photoTime = su.getRequest().getParameter(
"photoTime"); // ��ȡ����ϴ�ʱ��
String username = su.getRequest().getParameter(
"username"); // ��ȡ�ϴ��û���
String photoSize = String.valueOf(singleFile
.getSize()); // ��ȡ�ϴ��ļ��Ĵ�С
String filedir = "savefile/"
+ System.currentTimeMillis() + "."
+ singleFile.getFileExt(); // ��ϵͳʱ����Ϊ�ϴ��ļ����ƣ������ϴ��ļ�������·��
String smalldir = "saveSmall/"
+ System.currentTimeMillis() + "."
+ singleFile.getFileExt();
Photo photo = new Photo();
/** ********��photo�����е����Խ���һһ��ֵ*** */
photo.setPhotoName(photoName);
photo.setPhotoType(photoType);
photo.setPhotoSize(photoSize);
photo.setPhotoTime(photoTime);
photo.setUsername(username);
photo.setPhotoAddress(filedir);
photo.setSmallPhoto(smalldir);
/** ************************************ */
if (data.photo_save(photo)) { // ʵ���ϴ�������SQL���
singleFile.saveAs(filedir, File.SAVEAS_VIRTUAL); // ִ���ϴ�����
com.wy.tools.ImageUtils.createSmallPhoto(
request.getRealPath("/" + filedir),
request.getRealPath("/" + smalldir));
information = "�������Ƭ�ɹ�!";
}
}
}
}
}
} catch (Exception e) {
System.out.println(e);
}
request.setAttribute("information", information);
request.getRequestDispatcher("user_upLoadPhoto.jsp").forward(request,
response);
}