当前位置:首页 » 文件管理 » ssh上传图片

ssh上传图片

发布时间: 2022-01-24 20:48:53

⑴ ssh框架上传图片与显示

java">页面的form
<formaction="indexDetail.action"method="post"enctype="multipart/form-data">
图片:<inputtype="file"name="file"/><br/>
<inputtype="submit"name="imageField"class="btn_imgimg_submit"value="提交"/>
</form>

后台代码

//上传文件
privateFilefile;
privateStringfileFileName;

Stringrealpath=ServletActionContext.getServletContext().getRealPath("/images/ask/");
if(!newFile(realpath).exists()){
newFile(realpath).mkdir();
}
String[]typechoose=fileFileName.split("\.");
intichoose=typechoose.length;
Stringtype=ichoose>1?typechoose[ichoose-1]:"";
SimpleDateFormatsmat=newSimpleDateFormat("yyyyMMddHHmmss");
Stringnewfilname=smat.format(newDate())+"."+type;
Stringpath=realpath+"/"+newfilname;
FileUtil.saveFile(path,file);

核心代码都在里面

⑵ ssh 上传图片中的Action怎么写

package com.file.action;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport {
private File file;
private String contentType;
private String fileName;

@Override
public String execute() throws Exception {
File saveFile = new File("c:/download/" + fileName);
if (!saveFile.getParentFile().exists())
saveFile.getParentFile().mkdirs();
FileUtils.File(file, saveFile);// 复制文件
this.addFieldError("isSuccess", "文件上传成功!");
return SUCCESS;
}

public void setUploadContentType(String contentType) {
this.contentType = contentType;
}

public void setUpload(File file) {
this.file = file;
}

public void setUploadFileName(String fileName) {
this.fileName = fileName;
}
}

具体代码请看:

linux系统 SSH工具上传文件命令

scp 可以在 2个 linux 主机间复制文件;

命令基本格式:
scp [可选参数] file_source file_target

======
从 本地 复制到 远程
======
* 复制文件:
* 命令格式:
scp local_file remote_username@remote_ip:remote_folder
或者
scp local_file remote_username@remote_ip:remote_file
或者
scp local_file remote_ip:remote_folder
或者
scp local_file remote_ip:remote_file

⑷ 求一段 SSH上传图片的代码,只需要把路径存到数据库中即可

UploadActionForm uaf = (UploadActionForm)form; ///UploadActionForm 是封装了formbean的java类
System.out.println("title:"+uaf.getTitle());
FormFile myFile = uaf.getMyfile();
if(null != myFile) {
System.out.println("fileName:"+myFile.getFileName());
FileOutputStream fos = new FileOutputStream ("d:\\+你要上传到服务器的路径);
fos.write(myFile.getFileData());
fos.flush();
fos.close();
}

⑸ SSH 上传图片,如何获取项目的真实路径

使用Struts2的ServletActionContext可以得到项目的真实路径

假如,项目名称为BookSystem,部署到Tomcat的webapps目录下,则

Stringpath=ServletActionContext.getServletContext().getRealPath("/");

path取出的路径为:D:apache-tomcat-7.0.16webappsBookSystem

即:BookSystem项目部署到服务器的完整路径


取出上传路径,并保证路径存在的代码如下:

Action类中部分代码:
//取出当前项目部署在服务器上的路径
Stringpath=ServletActionContext.getServletContext().getRealPath("/");
//构建当前项目下的存放目录
StringfilePath=path+"images";
//构建文件对象
Filefolder=newFile(filePath);
//检测文件夹是否存在,如果不存在,则新建images目录
if(!folder.exists()){
folder.mkdir();
}

⑹ ssh 上传图片 只保存图片名称在数据库怎么做

这很简单啊,一般情况下上传文件都是提供一个文件选择框,也就是<input type="file" />给用户,用户选择文件后,浏览器会自动将文件名显示在文本框中,你只要将这个文件名取出来然后保存到数据库中就可以了

⑺ ssh中如何在上传的图片上生成水印

http://hi..com/ylwenxia/blog/item/9146aa011b817902738da5b3.html

得到上传的IO流,然后用上面的代码生成水印图片再储存起来

⑻ ssh2上传图片

在这儿把Struts2的上传图片的代码给你吧,其余的很简单,你自己再研究一下就会了啊!

public String insert() throws Exception {

// 保存文件

InputStream is = new FileInputStream(img);

String filePath = ServletActionContext.getServletContext().getRealPath(

"/upload")

+ "/";

String fileName = UUID.randomUUID().toString();

fileName += imgFileName.substring(imgFileName.lastIndexOf("."));

OutputStream os = new FileOutputStream(new File(filePath + fileName));

// 边读边写

byte[] data = new byte[1024];

int length = 0;

while ((length = is.read(data)) != -1) {

os.write(data, 0, length);

}

is.close();

os.close();

news.setImg(fileName);

boolean flag = newsService.insert(news);

message = flag ? "添加成功" : "添加失败";

path = "pages/news_list.action";

return "forward";

}

⑼ ssh上传图片怎么储存在项目里

一般的处理会存储到电脑的盘符里的,而不是tomcat下面的wepapp下面,“而我也试过存储在电脑的其他位置比如d盘,但是这样的结果是我的项目在服务器中运行后,用这个绝对路径服务器是找不到的,也就是说显示不出来。

这个是不太可能的,除非你的路径有问题。你可以在打开这个网站后用firebug调试看是不是有404错误。

⑽ ssh上传图片的问题

存链接,图片存硬盘里的

热点内容
python读写txt文件 发布:2024-10-18 22:21:37 浏览:362
网易版我的世界服务器语音交流 发布:2024-10-18 22:11:03 浏览:942
路由器限制上传速度 发布:2024-10-18 21:53:17 浏览:659
win7浏览器缓存文件 发布:2024-10-18 21:51:19 浏览:84
安卓如何调出系统界面 发布:2024-10-18 21:47:16 浏览:740
jetty源码debug 发布:2024-10-18 21:47:13 浏览:225
给料源码 发布:2024-10-18 21:43:30 浏览:833
手机配置不支持堡垒之夜怎么办 发布:2024-10-18 21:40:43 浏览:714
keil编译错误 发布:2024-10-18 21:34:28 浏览:987
下面赋值语句不会出现编译警告或错误 发布:2024-10-18 21:34:17 浏览:730