ftp实现图片上传,文件也类似
本来用得是easyui得控件 点击按钮实现选择图片得 ,但是老板非得要双击图片框实现上传代码。。。。做个简单得记录
前端代码:
首先,<form>表单要加上 enctype="multipart/form-data" 才能实现上传文件
然后这是
<div data-options="prompt:'图片展示'" id="img" style="text-algin:center;height:150px;width:205px;vertical-align:middle;border:1px solid #95B8E7;border-radius:5px" >
<img id="urlImg" width="205px" height="150px" ondblclick="fileSelect();">
</div>
下面是双击事件, 下面得是图片预览 ,上篇随笔介绍过了
function fileSelect() {
document.getElementById("fileToUpload").click();
}
$("#fileToUpload").change(function(){
$("#urlImg").attr("src",URL.createObjectURL($(this)[0].files[0]));
});
接下来的后端代码
数据库加了个url的字段,用来存储图片名称,名称是随机生成的
Action层:
//添加
public void insertSpecificMCodeInformation() { SpecificMCodeInformation specificMCodeInformation = new SpecificMCodeInformation(); //mCodeInformation.setTypeID(parentID+typeID);
//specificMCodeInformation.setTypeID(typeID);
specificMCodeInformation.setParentID(parentID);
specificMCodeInformation.setIllustration(illustration);
specificMCodeInformation.setTypeName(typeName);
specificMCodeInformation.setEntryUnit(entryUnit);
specificMCodeInformation.setAlias(alias);
specificMCodeInformation.setAlias1(alias1);
specificMCodeInformation.setAlias2(alias2);
specificMCodeInformation.setEntryPerson(entryPerson);
specificMCodeInformation.setEntryDate(DateStringUtil.DateToStr(new Date()));
specificMCodeInformation.setNorms(norms);
specificMCodeInformation.setModel(model);
specificMCodeInformation.setUrl(url);
if( fileToUpload != null ) {
// 统一调用一个上传方法,方便后期维护
String img = specificMCodeInformationService.saveContImg(fileToUpload, fileToUploadFileName, typeID);
specificMCodeInformation.setUrl(img);
System.out.println("IMGGGGGGGGGGGGGGGGG"+specificMCodeInformation.getUrl());
} specificMCodeInformationService.insertSpecificMCodeInformation(specificMCodeInformation);
writeJson(specificMCodeInformation);
}
DAO层:
public int insertSpecificMCodeInformation(@Param("specificMCodeInformation")SpecificMCodeInformation specificMCodeInformation);
Service层:
public void insertSpecificMCodeInformation(SpecificMCodeInformation specificMCodeInformation);
public String saveContImg( File upload, String uploadFileName, String typeID );
实现层:
@Override
public void insertSpecificMCodeInformation(SpecificMCodeInformation specificMCodeInformation) {
// TODO Auto-generated method stub
try {
System.out.println(createTypeID(specificMCodeInformation.getParentID()));
System.out.println("alias:"+specificMCodeInformation.getAlias());
System.out.println("norms:"+specificMCodeInformation.getNorms());
System.out.println("model:"+specificMCodeInformation.getModel());
System.out.println("entryUnit:"+specificMCodeInformation.getEntryUnit());
specificMCodeInformation.setTypeID(createTypeID(specificMCodeInformation.getParentID()));
System.out.println("typeID"+specificMCodeInformation.getTypeID());
System.out.println("url"+specificMCodeInformation.getUrl());
specificInformationMapper.insertSpecificMCodeInformation(specificMCodeInformation);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} }
这个用来生成文件名:
@Override
public String saveContImg(File fileToUpload, String fileToUploadFileName, String typeID) {
String saveFileName = "";
FTPUtil f = new FTPUtil();
try {
String ip = ReadProperty.getValue( "common.properties", "ftp.url" );
String username = ReadProperty.getValue( "common.properties", "ftp.username" );
String password = ReadProperty.getValue( "common.properties", "ftp.password" );
String port = ReadProperty.getValue( "common.properties", "ftp.port" );
int iPort = Integer.valueOf( port );
f.initClient( ip, iPort, username, password );
InputStream in = new FileInputStream( fileToUpload );
System.out.println("INNNN"+in);
String path = ReadProperty.getValue( "common.properties", "ftp.materiel" ) + typeID + "\\";
System.out.println("PATHHHHH"+path);
saveFileName = GUID.getGUID() + fileToUploadFileName.substring( fileToUploadFileName.lastIndexOf( "." ) );
System.out.println("FILENameEEEEE"+saveFileName);
f.upLoadFile( path, saveFileName, in );
} catch( Exception e ) {
e.printStackTrace();
} finally {
f.closeConnection();
}
return saveFileName; }
实体层不写了
ftp实现图片上传,文件也类似的更多相关文章
- FTP主动模式上传文件时返回"ftp: accept: Resource temporarily unavailable"
FTP主动模式上传文件时返回 Passive mode off ftp: accept: Resource temporarily unavailable 这个问题要从ftp的2种模式说起 PORT ...
- FTP与HTTP上传文件的对比
许多站点,比如facebook或一些博客等都允许用户上传或下载文件,比如论坛或博客系统的图片. 在这种情况下,通常有两种选择上传文件到服务器,那就是FTP协议和HTTP协议. 以下列出了一些两者的不同 ...
- ftp配置 Laravel上传文件到ftp服务器
listen=YES anonymous_enable=NO local_enable=YES write_enable=YES local_umask= dirmessage_enable=YES ...
- java使用JSCH连接FTP(Linux服务器)上传文件到Linux服务器
首先需要用到jsch-0.1.54.jar 包: 链接: https://pan.baidu.com/s/1kZR6MqwpCYht9Pp_D6NKQw 密码: gywx 直接上代码: package ...
- php 图片上传 文件上传 大小 限制
nginx 413 Request Entity Too Large Php无法上传文件 查看php脚本运行用户,写个php脚本 <?php echo shell_exec("id ...
- Ftp客户端(上传文件)
#coding=utf-8 import os import socket import hashlib import json # client = socket.socket() #申明socke ...
- FTP FtpWebRequest 异步上传文件
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- ftp服务器不能上传文件故障
1.在客户端lftp命令无法put文件 原因:登陆用户无法读写 ftp服务器的文件夹,在服务器上增加权限 chmod 777 即可 还有一种方法:在 vsftp的配置文件里,设置可匿名读写
- ftp免交互上传文件脚本
ftp -i -n <<! open .x.x.x user yourFtpAccount yourPasswd cd /root/DailyBuild/webapps/ delete x ...
随机推荐
- [Recompose] Pass a React Prop to a Stream in RxJS
When you declare your Component and Props in JSX, you can pass those props along to your RxJS stream ...
- hdoj--3549--Flow Problem(最大流)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- BZOJ 4144 Dijkstra+Kruskal+倍增LCA
思路: 先把所有的加油站 push进按weight排序的优先队列里 对于每个不是加油站的点 找到到它的点的最短路以及它来源的加油站 如果x和y有边 且x和y加油站的来源不一样 则它可以连边 跑一边Kr ...
- 用iptables抗御SYN Flood攻击
1 引 言 网络安全是各种网络应用面临的一个首要问题.从网络普及的那天开始,网络犯罪就没有停止过,相反有愈演愈烈之势.研究发现,现今的网络攻击以分布式拒绝服务攻击(DDOS)为主 .其 ...
- POJ 1610 Count the Colors
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- Juniper Alarms 灯红色报警处理
1.2.5.1告警查看 root# run show system alarms 2 alarms currently active Alarm time Class Description 2015 ...
- Linux系统中命令提示符解释-Linux中命令格式、分类-bash中的快捷键
1.命令提示符 [root@mysqlserver01 opt]# [root@mysqlserver01 ~]# root 当前用户名 @ 固定的(格式) mysqlserver01 主机名 opt ...
- 今日SGU 5.14
//SGU 131 还没完全想清楚 留坑 SGU 259 题意:一个机器处理n个任务,每个任务有时间t和传送时间l 收获:贪心 #include<bits/stdc++.h> #defin ...
- C# 调用者信息特性(Attribute)
.NET 4.5中引用了三种特性(Attribute), 该特性允许获取调用者的当前编译器的执行文件名.所在行数与方法或属性名称. 命名空间 System.Runtime.CompilerServic ...
- Android性能优化之提高ListView性能的技巧
ListView优化一直是一个老生常谈的问题.无论是面试还是寻常的开发中,ListView永远不会被忽略掉,那么这篇文章我们来看看怎样最大化的优化ListView的性能. 1.在adapter中的ge ...