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 ...
随机推荐
- 减少UIViewController切换的耦合
我们一般切换UIViewController的时候用的是例如以下代码 #import "UIViewControllerDemo.h" UIViewControllerDemo * ...
- 轻松python专题--文本
基础篇:(取材于零基础学python) 7.1 python中的字符串简单介绍与经常使用函数 7.2 字符串常量 7.3 字符串的一般使用 7.4 改动字符串实例 7.5 文本解析 7.6 字符串格式 ...
- django 笔记2
默默坚持 :路由系统 URL :视图 request.GET request.POST request.FILES #checkbox等多选的内容 request.POST.getlist() #上传 ...
- BZOJ 1012 单调队列+二分
思路: 维护一个单减的序列 序号是单增的 每回二分查找第一个比询问的大的值 我手懒 用得lower_bound //By SiriusRen #include <cstdio> #incl ...
- rev---将文件中的每行内容以字符为单位反序输出
rev命令将文件中的每行内容以字符为单位反序输出,即第一个字符最后输出,最后一个字符最先输出,依次类推.
- Centos6.5 安装lnmp环境
最近项目要配置在nginx上,所以搜索了下具体nginx的安装,看到这篇文章简洁明了而且测试成功就借用了,作品出处:http://www.cnblogs.com/xiaoit/p/3991037.ht ...
- 使用scatter画散点图
刚开始接触Python,照着例子写的代码,百度注释的. from numpy import * import matplotlib import matplotlib.pyplot as plt im ...
- leetcode第一刷_Scramble String
字符串的好题. 题干解释的很复杂.一下让人不知所措了. 这道题究竟是什么意思呢?终于的结果是把一个字符串中字母的顺序打乱了,让你推断一个字符串能不能由还有一个字符串打乱得到.那打乱这个过程是怎么做的呢 ...
- [Python] Find available methods and help in REPL
For example you want to know what methods are available in Python for String, you can do : dir(" ...
- rtsp和sdp协议简介
RTSP是由Real network 和Netscape共同提出的如何有效地在IP网络上传输流媒体数据的应用层协议. 实时流协议(RTSP)建立并控制一个或几个时间同步的连续流媒体,如音频和视频.尽管 ...