文件上传方式
来源:互联网 发布:双拼域名注册大师 编辑:程序博客网 时间:2024/05/29 09:06
1.文件的上传(sqlite文本数据库)
页面:<tr height="30" bgcolor="#F1F1F1">
<td width="128" class="tb11">图片</td>
<td class="tb12"><input type="file" name="img">
<span id="note-devicename"> </span></td>
</tr>
后台中操作
if (img == null) {
throw new RuntimeException("请上传图片!");//判断数据是否上传的值}
if (img.indexOf(".") == -1) {
throw new RuntimeException("您上传的文件无法获得后缀名!");//判断数据上传的值中是否拥有
}
String temp = img.substring(img.indexOf(".") + 1, img.length());//获取文件的后缀名
if (!temp.equals("bmp") && !temp.equals("dib") && !temp.equals("gif")//判断后缀名的格式
&& !temp.equals("jpe") && !temp.equals("jpeg")
&& !temp.equals("jpg") && !temp.equals("png")
&& !temp.equals("ico")) {
throw new RuntimeException(
"您上传的图片格式不符合要求,请确定上传的是bmp/gif/jpg/ico/png/jpeg格式!");
}
File file = new File(getFiles().get("img").toString());//获取文件
if (!file.exists()) {
throw new RuntimeException("请上传图片!");
}
String newImg = "img/" + UUID.randomUUID();//给其一个随机的名称
FileUtils.copyFile(file, new File(Http.baseUrl + newImg));//public class Http extends NanoHTTPD {public static String baseUrl = "sdcard/web/";文件的copy的文件
area.setImg(newImg);//将文件的新名称导入到数据库中
AreaControl.areaDao.insert(area);
- Servlet方式文件上传
- 文件上传方式
- Ajax方式上传文件
- Ajax方式上传文件
- Ajax方式上传文件
- Ajax方式上传文件
- POST方式上传文件
- 窗体上传文件方式
- javascript 文件上传方式
- Ajax方式上传文件
- ajax方式上传文件
- 原生方式上传文件
- 文件上传方式2
- Ajax方式上传文件
- 几种上传文件方式
- Winform 上传文件(ftp方式)
- Winform 上传文件(ftp方式)
- Winform 上传文件(ftp方式)
- exec系列函数
- openfire 集成现有平台用户
- Oracle中instr函数用法
- System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
- Oracle安装过程中出现:ORA-00922:选项缺失或无效问题解决办法
- 文件上传方式
- C#打印窗口
- HBase 学习笔记三---守护进程及内存调优
- android图片闪烁或帧动画
- 字符集例子-同一字符不同字符集编码不同及导入导出的乱码
- document.all
- QTP运行缓慢的常见原因
- iOS中的模糊效果
- 自动化测试的发展前景