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 ...
随机推荐
- TortoiseSvn安装的时候,将svn的命令行工具单独隔离出来
https://stackoverflow.com/questions/2967176/where-is-svn-exe-in-my-machine The subversion program co ...
- “DNS隧道”盗号木马分析——类似hjack偷密码然后利用dns tunnel直传数据发送出去
摘自:http://www.freebuf.com/articles/network/38276.html# 运行后不断监控顶端窗口,一旦发现为QQ,就弹出一个自己伪造的QQ登陆窗口,诱导用户输入密码 ...
- beego简单的验证码实现以及验证
/** * 程序 */package controllers import ( "github.com/astaxie/beego" "github.com/ ...
- Weka中数据挖掘与机器学习系列之Weka Package Manager安装所需WEKA的附加算法包出错问题解决方案总结(八)
不多说,直接上干货! Weka中数据挖掘与机器学习系列之Weka系统安装(四) Weka中数据挖掘与机器学习系列之Weka3.7和3.9不同版本共存(七) 情况1 对于在Weka里,通过Weka P ...
- 记录一下Memcached的用法:
首先就是先要配置Memcached,这个回头再写. https://zhidao.baidu.com/question/809745125827797732.html https://www.cnbl ...
- js实现导出数据到excel
来自:http://www.imooc.com/article/13374 //html代码<!DOCTYPE HTML> <html> <head> <ti ...
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
- Linux桌面词典 GoldenDict词典
GoldenDict 是一款不错的.与StarDict(星际译王)类似的词典软件.它使用 WebKit作为渲染核心,格式化.颜色.图像.链接等支持一应俱全:支持多种词典文件格式,包括Babylon的 ...
- 织梦DedeCMS会员登录或退出后如何直接跳转到首页
织梦dedecms默认情况下的会员登录后会直接跳转到会员中心,退出也是一样,但是如果我们想让会员登录后直接跳转到首页,那该如何实现呢? 经过我们的研究,已经找到解决办法,下面是详细的修改步骤: 首先在 ...
- BZOJ一句话
一句话题解集合. 1061: [Noi2008]志愿者招募 单纯形,运用对偶原理转化过来,变成标准形然后单纯性裸上即可. #include<cmath> #include<cstdi ...