當前位置:首頁 » 文件管理 » 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上傳圖片的問題

存鏈接,圖片存硬碟里的

熱點內容
license伺服器是什麼 發布:2024-10-18 20:13:56 瀏覽:975
我的世界電腦幾種最好玩的伺服器 發布:2024-10-18 20:10:22 瀏覽:399
手機聯系人雲存儲 發布:2024-10-18 19:56:04 瀏覽:529
dnd編程 發布:2024-10-18 19:37:58 瀏覽:110
matlab編程學習 發布:2024-10-18 19:12:53 瀏覽:456
c語言賦值函數 發布:2024-10-18 19:10:43 瀏覽:967
ftp3級 發布:2024-10-18 18:57:11 瀏覽:45
python的zip 發布:2024-10-18 18:56:05 瀏覽:574
sql2008清理日誌 發布:2024-10-18 18:38:37 瀏覽:462
linux實戰項目 發布:2024-10-18 18:30:20 瀏覽:359