upload
<%@ page import="com.letdoo.pic.base.DateUtil" %>
<%@ page import="com.letdoo.video.dao.*" %>
<%
//写入数据库初始化
ApplicationContextFactory.init("/com/letdoo/pic/DAO/applicationContext-hibernate.xml");
VideoDao videoDao = (VideoDao) ApplicationContextFactory.getApplicationContext().getBean("videoDao");
VideoLibCategroyDao videoLibCategroyDao = (VideoLibCategroyDao) ApplicationContextFactory.getApplicationContext().getBean("videoLibCategroyDao");
//得到参数初试化
String temp = getServletContext().getRealPath("/") + "upload";
String createFilePath = getServletContext().getRealPath("/") + "upload" + File.separator +"video";
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(100*1024*1024);
fu.setSizeThreshold(4096);
fu.setRepositoryPath(temp);
fu.setHeaderEncoding("gbk");
List fileItems = fu.parseRequest(request);
Iterator iter = fileItems.iterator();
FileItem item = null;
String names = null;
String value = null;
uploadUtil u = new uploadUtil();
for(int i=0,n=fileItems.size()-2; i<n; i++) {
item = (FileItem) iter.next();
if (item.isFormField()) {
names = item.getFieldName();
value = item.getString("gbk");
u.setField(names,value);
}
}
String namess = u.getParameter("name");
String desc = u.getParameter("desc");
String tag = u.getParameter("tag");
//创建数据库记录
VideoLibCategroy vv = videoLibCategroyDao.findVideoLibCategroyById(u.getParameter("cateId"));
Video v = new Video();
v.setCreateTime(new Date());
v.setName(namess);
v.setState(0);
v.setTag(tag);
v.setDesc(desc);
v.setSurffix("jpg");
v.setFileSize(100);
v.setPointCounts(0);
v.setPoints(0);
VideoLibRCateVideo vr = new VideoLibRCateVideo();
vr.setVideo(v);
vr.setVideoLibCategroy(vv);
v.getVideoLibRCateVideo().add(vr);
videoDao.addVideo(v);
//得到Id,并计算生成路径
String fileName = v.getId();
createFilePath = createFilePath + File.separator + DateUtil.getYearMonth(v.getCreateTime());
//上传文件。。。
String imageName = null, videoFileSuffix = null, _name, _surffix, _newName;
int videoFileSize = 0, _fileSize;
//图片
try {
item = (FileItem) iter.next();
_name = item.getName();
_name = _name.substring(_name.lastIndexOf("\\")+1); //only for windows
int dotPos = _name.lastIndexOf(".");
if (dotPos>0) {
_surffix = _name.substring(dotPos+1);
}
else {
_surffix = "";
}
_newName = fileName + "." + _surffix; //fileName == id
_fileSize = (int) item.getSize();
File _category = new File(createFilePath);
if (!_category.exists()) {
_category.mkdirs();
}
File _fileNew = new File(_category, _newName);
item.write(_fileNew);
_fileNew = null;
_category = null;
//
imageName = _newName;
}
catch(java.io.IOException ioe) {
ioe.printStackTrace();
}
//视频
try {
item = (FileItem) iter.next();
_name = item.getName();
_name = _name.substring(_name.lastIndexOf("\\")+1); //only for windows
int dotPos = _name.lastIndexOf(".");
if (dotPos>0) {
_surffix = _name.substring(dotPos+1);
}
else {
_surffix = "";
}
_newName = fileName + "." + _surffix; //fileName == id
_fileSize = (int) item.getSize();
File _category = new File(createFilePath);
if (!_category.exists()) {
_category.mkdirs();
}
File _fileNew = new File(_category, _newName);
item.write(_fileNew);
_fileNew = null;
_category = null;
//
videoFileSuffix = _surffix;
videoFileSize = _fileSize;
}
catch(java.io.IOException ioe) {
ioe.printStackTrace();
}
//end of 上传文件
//回写视频信息
v.setShowImage(imageName); //图片名称
v.setFileSize(videoFileSize); //视频文件大小
v.setSurffix(videoFileSuffix); //视频文件后缀
videoDao.updateVideo(v);
%>
<script language="JavaScript">
window.close();
window.opener.location.reload();
</script>
<%@ page import="com.letdoo.video.dao.*" %>
<%
//写入数据库初始化
ApplicationContextFactory.init("/com/letdoo/pic/DAO/applicationContext-hibernate.xml");
VideoDao videoDao = (VideoDao) ApplicationContextFactory.getApplicationContext().getBean("videoDao");
VideoLibCategroyDao videoLibCategroyDao = (VideoLibCategroyDao) ApplicationContextFactory.getApplicationContext().getBean("videoLibCategroyDao");
//得到参数初试化
String temp = getServletContext().getRealPath("/") + "upload";
String createFilePath = getServletContext().getRealPath("/") + "upload" + File.separator +"video";
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(100*1024*1024);
fu.setSizeThreshold(4096);
fu.setRepositoryPath(temp);
fu.setHeaderEncoding("gbk");
List fileItems = fu.parseRequest(request);
Iterator iter = fileItems.iterator();
FileItem item = null;
String names = null;
String value = null;
uploadUtil u = new uploadUtil();
for(int i=0,n=fileItems.size()-2; i<n; i++) {
item = (FileItem) iter.next();
if (item.isFormField()) {
names = item.getFieldName();
value = item.getString("gbk");
u.setField(names,value);
}
}
String namess = u.getParameter("name");
String desc = u.getParameter("desc");
String tag = u.getParameter("tag");
//创建数据库记录
VideoLibCategroy vv = videoLibCategroyDao.findVideoLibCategroyById(u.getParameter("cateId"));
Video v = new Video();
v.setCreateTime(new Date());
v.setName(namess);
v.setState(0);
v.setTag(tag);
v.setDesc(desc);
v.setSurffix("jpg");
v.setFileSize(100);
v.setPointCounts(0);
v.setPoints(0);
VideoLibRCateVideo vr = new VideoLibRCateVideo();
vr.setVideo(v);
vr.setVideoLibCategroy(vv);
v.getVideoLibRCateVideo().add(vr);
videoDao.addVideo(v);
//得到Id,并计算生成路径
String fileName = v.getId();
createFilePath = createFilePath + File.separator + DateUtil.getYearMonth(v.getCreateTime());
//上传文件。。。
String imageName = null, videoFileSuffix = null, _name, _surffix, _newName;
int videoFileSize = 0, _fileSize;
//图片
try {
item = (FileItem) iter.next();
_name = item.getName();
_name = _name.substring(_name.lastIndexOf("\\")+1); //only for windows
int dotPos = _name.lastIndexOf(".");
if (dotPos>0) {
_surffix = _name.substring(dotPos+1);
}
else {
_surffix = "";
}
_newName = fileName + "." + _surffix; //fileName == id
_fileSize = (int) item.getSize();
File _category = new File(createFilePath);
if (!_category.exists()) {
_category.mkdirs();
}
File _fileNew = new File(_category, _newName);
item.write(_fileNew);
_fileNew = null;
_category = null;
//
imageName = _newName;
}
catch(java.io.IOException ioe) {
ioe.printStackTrace();
}
//视频
try {
item = (FileItem) iter.next();
_name = item.getName();
_name = _name.substring(_name.lastIndexOf("\\")+1); //only for windows
int dotPos = _name.lastIndexOf(".");
if (dotPos>0) {
_surffix = _name.substring(dotPos+1);
}
else {
_surffix = "";
}
_newName = fileName + "." + _surffix; //fileName == id
_fileSize = (int) item.getSize();
File _category = new File(createFilePath);
if (!_category.exists()) {
_category.mkdirs();
}
File _fileNew = new File(_category, _newName);
item.write(_fileNew);
_fileNew = null;
_category = null;
//
videoFileSuffix = _surffix;
videoFileSize = _fileSize;
}
catch(java.io.IOException ioe) {
ioe.printStackTrace();
}
//end of 上传文件
//回写视频信息
v.setShowImage(imageName); //图片名称
v.setFileSize(videoFileSize); //视频文件大小
v.setSurffix(videoFileSuffix); //视频文件后缀
videoDao.updateVideo(v);
%>
<script language="JavaScript">
window.close();
window.opener.location.reload();
</script>
haohao
2006-06-23 18:49:27
评论:0
阅读:154
引用:0